Henry_he @ 2017-05-25 18:02:54
var a,b,c:array[1..50]of longint;
f:array[0..100000]of int64;
n,i,j,t,t1,ans:longint;
function max(x,y:int64):int64;
begin
if x>y then exit(x)
else exit(y);
end;
begin
readln(t,n);
for i:=1 to n do
read(a[i]);
for i:=1 to n do
read(b[i]);
for i:=1 to n do
read(c[i]);
for i:=1 to n-1 do
for j:=i+1 to n do
begin
if c[i]*b[j]>c[j]*b[i] then
begin
t1:=a[i];
a[i]:=a[j];
a[j]:=t1;
t1:=b[i];
b[i]:=b[j];
b[j]:=t1;
t1:=c[i];
c[i]:=c[j];
c[j]:=t1;
end;
end;
for i:=1 to n do
for j:=t downto c[i] do
f[j]:=max(f[j],f[j-c[i]]+a[i]-b[i]*(t-j));
for i:=1 to t do
ans:=max(ans,f[i]);
writeln(ans);
end.