Pagini recente » Cod sursa (job #2914397) | Cod sursa (job #837909) | Cod sursa (job #1438155) | Cod sursa (job #1111488) | Cod sursa (job #681549)
Cod sursa(job #681549)
var pr:array [1..2, 0..10000] of longint;
i, j, n, m, x, y:longint;
f, g:text;
buf1:array [1.. 1 shl 17] of char;
function max(fa, fb:longint):longint; begin if fa>fb then max:=fa else max := fb; end;
begin
assign (f, 'rucsac.in'); settextbuf (f, buf1); reset (f);
assign (g, 'rucsac.out'); rewrite (g);
read (f, n, m);
for i := 1 to n do
begin
read (f, x, y);
for j := 1 to m do
begin
if x <= j then
begin
pr[2, j]:=max(pr[1, j], pr[1, j-x]+y);
end
else
begin
pr[2, j]:= pr[1, j];
end;
end;
for j := 1 to m do pr[1, j]:=pr[2, j];
end;
writeln (g, pr[2, m]);
close (f); close (g);
end.