Pagini recente » Cod sursa (job #2838593) | Cod sursa (job #1405798) | Cod sursa (job #2249317) | Cod sursa (job #2977013) | Cod sursa (job #929338)
Cod sursa(job #929338)
var g, c, a, t: array[0..10000] of integer;
n, i, j, gmax: integer;
function max: integer;
begin
max:=a[j];
if j-g[i]>=0 then
if a[j]<(a[j-g[i]]+c[i]) then max:=a[j-g[i]]+c[i];
end;
procedure tr;
var i: integer;
begin
for i:=1 to gmax do a[i]:=t[i];
end;
begin
assign(input,'rucsac.in');
reset(input);
assign(output,'rucsac.out');
rewrite(output);
readln(n, gmax);
for i:=1 to n do readln(g[i], c[i]);
for i:=0 to gmax do a[i]:=0;
for i:=1 to n do Begin
for j:=1 to gmax do if g[i]<=j then t[j]:=max; tr;
end;
writeln(a[gmax]);
close(input);
close(output);
end.