Pagini recente » Cod sursa (job #346564) | Cod sursa (job #122053) | Cod sursa (job #462356) | Cod sursa (job #2502168) | Cod sursa (job #1161666)
var a:array[1..3,0..1005] of longint;
c,e:array[1..5004] of longint;
i,n,g,j:integer;
f_in,f_out:text;
function max(x,y:longint):longint;
begin
if x>y then max:=x
else max:=y;
end;
begin
assign(f_in,'rucsac.in');reset(f_in);
assign(f_out,'rucsac.out');rewrite(f_out);
readln(f_in,n,g);
for i:=1 to n do readln(f_in,c[i],e[i]);
for i:=1 to n do
begin
for j:=1 to g do
begin
a[2,j]:=a[1,j];
if c[i]<=j then a[2,j]:=max(a[1,j],a[1,j-c[i]]+e[i]);
end;
for j:=1 to g do
a[1,j]:=a[2,j];
end;
writeln(f_out,a[2,g]);
close(f_in);
close(f_out);
end.