Pagini recente » Cod sursa (job #1698809) | Cod sursa (job #1726007) | Cod sursa (job #1146211) | Cod sursa (job #2279660) | Cod sursa (job #1174517)
Program dinam;
var i,j,n,m,a,b,Pmax : longint;
G : array[1..10000] of longint;
begin
assign(input,'rucsac.in'); reset(input);
assign(output,'rucsac.out'); rewrite(output);
readln(n,m);
Pmax:=0;
for i:=1 to n do begin
readln(a,b);
for j:=m downto a do
if G[j-a]+b>G[j] then G[j]:=G[j-a]+b;
end;
for i:=m downto 1 do
if G[i]>Pmax then Pmax:=G[i];
writeln(Pmax);
close(input);
close(output);
end.