Pagini recente » Cod sursa (job #2561083) | Cod sursa (job #951356) | Cod sursa (job #1672972) | Cod sursa (job #3173742) | Cod sursa (job #1690153)
program rucsac;
var i, j, g, n, m : longint;
w, p : array[1..5000] of integer;
a : array[0..10000] of integer;
begin
assign(input, 'rucsac.in');
reset(input);
read( n, g);
for i:=1 to n do read(w[i], p[i]);
a[0]:=0; m:=0;
for i:=1 to n do begin
for j:=g downto w[i] do begin
if w[i]<j then begin
if a[j-w[i]]+p[i]>a[j] then a[j]:=a[j-w[i]]+p[i];
if m<a[j] then m:=a[j];
end; end;end;
assign(output, 'rucsac.out');
rewrite(output);
write(m);
end.