Pagini recente » Cod sursa (job #1568382) | Cod sursa (job #49727) | Cod sursa (job #1358183) | Cod sursa (job #2602756) | Cod sursa (job #1106657)
var n,i , j, Max: integer;
a: array[0..10000] of longint;
c, g: array[1..10000] of integer;
s: longint;
function Maxim(a, b: integer): integer;
begin
if a>b then maxim:=a
else maxim:=b;
end;
begin
assign(input,'rucsac.in');
reset(input);
assign(output,'rucsac.out');
rewrite(output);
readln(n, max);
for i:=1 to n do readln(g[i], c[i]);
for i:=0 to max do a[i]:=0;
s:=0;
for i:=1 to n do
for j:=(max-g[i]) downto 0 do
Begin
a[j+g[i]]:=Maxim(a[j+g[i]], a[j]+c[i]);
if a[j+g[i]]>s then s:=a[j+g[i]];
end;
writeln(s);
close(input);
close(output);
end.