同问
by cy1999 @ 2016-03-02 23:40:43
```cpp
var a:array [0..50000] of longint;
i,j,v,s,n,m,x,max:longint;
begin
read(n,m);
a[0]:=1;
for i:=1 to m do begin
read(v,s);
x:=v*s;
for j:=n-v downto 0 do
if a[j]<>0 then
if (a[j]+x>a[j+v]) then a[j+v]:=a[j]+x;
end;
for i:=0 to n do
if a[i]>max then max:=a[i];
write(max-1);
end.
```
by Mr张 @ 2016-09-30 16:40:03