Pagini recente » Cod sursa (job #2931723) | Cod sursa (job #1975057) | Cod sursa (job #2789113) | Cod sursa (job #2695642) | Cod sursa (job #1707462)
program rucsac;
var n,g,i,j,max:longint;
w,p,op:array[0..10000] of longint;
begin
assign(input,'rucsac.in');
assign(output,'rucsac.out');
reset(input);
rewrite(output);
read(n,g);
for i:=1 to n do read(w[i],p[i]);
op[0]:=0;
max:=0;
for i:=1 to n do begin
for j:=g downto w[i] do begin
if op[j-w[i]]+p[i]>op[j] then
op[j]:=op[j-w[i]]+p[i];
if op[j]>max then max:=op[g];
end;
end;
write(max);
end.