Pagini recente » Cod sursa (job #2143767) | Statistici Hajnal George Florin (Georgehajnal) | Cod sursa (job #1615863)
program rucsac;
var f,g:text;
greutate,cost:array[1..100000] of longint;
b:array[0..100000] of int64;
n,gr,i,j:longint;
max:int64;
begin
assign(f,'rucsac.in');
assign(g,'rucsac.out');
reset(f);
rewrite(g);
readln(f,n,gr);
for i:=1 to n do
begin
readln(f,greutate[i],cost[i]);
end;
for i:=1 to n do
for j:=gr-greutate[i] downto 0 do
if b[j+greutate[i]]<b[j]+cost[i] then
begin
b[j+greutate[i]]:=b[j]+cost[i];
if b[j+greutate[i]]>max then
max:=b[j+greutate[i]];
end;
writeln(g,max);
close(f);
close(g);
end.