邢鹏程 2010-10-30 02:35:00
点我顶贴
收藏
删除
var m,n,i,j:integer;
s:longint;
a,b,c:array[0..30] of integer;
begin
readln(m,n);
for i:=1 to n do
begin
readln(a[i],b[i]);
c[i]:=a[i]*b[i];
end;
for i:=1 to n do
for j:=n downto i+1 do
if c[j-1]>c[j] then
begin
c[0]:=c[j-1];
c[j-1]:=c[j];
c[j]:=c[0];
end;
for i:=n downto 1 do
if s>m*n then exit;
if s<=m*n then s:=c[i]+s;
writeln(s);
end.