Pagini recente » Cod sursa (job #2504693) | Cod sursa (job #1414434) | Cod sursa (job #40097) | Cod sursa (job #1941563) | Cod sursa (job #680670)
Cod sursa(job #680670)
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..2,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.