Pagini recente » Cod sursa (job #1266909) | Cod sursa (job #980633) | Cod sursa (job #2130773) | Cod sursa (job #1217935) | Cod sursa (job #929340)
Cod sursa(job #929340)
var g, c, a, t: array[0..10000] of longint;
n, i, j, gmax: longint;
function max: longint;
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: longint;
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.