Pagini recente » Cod sursa (job #2331965) | Cod sursa (job #1365677) | Cod sursa (job #3161918) | Cod sursa (job #587395) | Cod sursa (job #680667)
Cod sursa(job #680667)
program sss;
type rrr=record
cast,greu:longint;
end;
var f,g:text;
n,gr,i,j,l:longint;
v:array[1..5005] of rrr;
a:array[0..5005,1..5005] of longint;
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.