Pagini recente » Cod sursa (job #2389073) | Cod sursa (job #457840) | Cod sursa (job #457836) | Cod sursa (job #2438545) | Cod sursa (job #1180375)
type tab=array[0..5010] of longint;
tab2=array[1..2,0..10010] of longint;
var a,b:text;
i,mass,n,j,q,p:longint;
m,v:tab;
t:tab2;
function max(x,y:longint):longint;
begin
if x>y then max:=x else max:=y;
end;
begin
assign(a,'rucsac.in'); reset(a);
assign(b,'rucsac.out'); rewrite(b);
readln(a,n,mass);
for i:=1 to n do
begin
readln(a,m[i],v[i]);
end;
for i:=1 to n do
for j:=1 to mass do
begin
q:=2; p:=1;
if i mod 2=0 then begin q:=1; p:=2; end;
if (j-m[i])>=0 then
if (t[q,j])>(v[i]+t[q,j-m[i]]) then t[p,j]:=t[q,j] else t[p,j]:=t[q,j-m[i]]+v[i] else t[p,j]:=t[q,j]
end;
writeln(max(t[2,j],t[1,j]));
close(a);
close(b);
end.