- 采药
- 2015-07-21 14:27:09 @
var i,j,m,n,p,x,mid,s,y:longint;
a,b:array[1..101] of longint;
procedure ttt(l,r:longint);
begin
i:=l; j:=r; mid:=b[(l+r)div 2];
repeat
while b[i]>mid do inc(i);
while b[j]<mid do dec(j);
if i<=j then
begin
p:=b[i]; b[i]:=b[j]; b[j]:=p;
x:=a[i]; a[i]:=a[j]; a[j]:=x;
inc(i); dec(j);
end;
until i>j;
if l<j then ttt(l,j);
if i<r then ttt(i,r);
end;
begin
read(m,n);
for i:=1 to n do
read(a[i],b[i]);
ttt(1,n);
y:=1;
repeat
if m=0 then exit;
m:=m-a[y];
if m>=0 then s:=s+b[y];
y:=y+1;
until (m<=0) or (y>n);
writeln(s);
end.
0 条评论
目前还没有评论...