Pagini recente » Cod sursa (job #1215365) | Cod sursa (job #2863326) | Cod sursa (job #2206630) | Cod sursa (job #2886732) | Cod sursa (job #1568102)
program rucsac;
var x,v:array of longint;
n,g:longint;
f,h:text;
procedure citiredinamica;
var i,gr,val,j:longint;
begin
assign(f,'rucsac.in');reset(f);
readln(f,n,g);
setlength(x,g+1);
for i:=1 to n do
x[i]:=0;
for i:=1 to n do
begin
readln(f,gr,val);
for j:=g downto 1 do
if gr<=j then
begin
if x[j]<x[j-gr]+val then
x[j]:=x[j-gr]+val
else
x[j]:=x[j];
end
else
x[j]:=x[j];
end;
close(f);
end;
procedure afisare;
begin
assign(h,'rucsac.out');rewrite(h);
writeln(h,x[g]);
close(h);
end;
begin
citiredinamica;
afisare;
end.