Pagini recente » Cod sursa (job #269850) | Cod sursa (job #964355) | Cod sursa (job #896938) | Cod sursa (job #754460) | Cod sursa (job #680673)
Cod sursa(job #680673)
program sss;
type rrr=record
cast,greu:qword;
end;
var f,g:text;
n,gr,l:qword;
i,j:longint;
v:array[1..5005] of rrr;
a:array[0..2,1..5005] of qword;
begin
assign(f,'rucsac.in'); reset(f);
assign(g,'rucsac.out'); rewrite(g);
readln(f,n,gr);
for i:=1 to n do
begin
readln(f,v[i].greu,v[i].cast);
end;
l:=0;
for i:=1 to n do
begin
for j:=0 to gr do
begin
a[1-l,j]:=a[l,j];
if v[i].greu<=j then
if v[i].cast+a[l,j-v[i].greu]>a[1-l,j] then
a[1-l,j]:=v[i].cast+a[l,j-v[i].greu];
end;
l:=1-l;
end;
write(g,a[l,gr]);
close(f);
close(g);
end.