Cod sursa(job #1106648)
Utilizator | Data | 12 februarie 2014 23:11:54 | |
---|---|---|---|
Problema | Problema rucsacului | Scor | 10 |
Compilator | fpc | Status | done |
Runda | Arhiva educationala | Marime | 0.59 kb |
var n,i , j, Max: integer;
a: array[0..10000] of longint;
c, g: array[1..10000] of integer;
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;
for i:=1 to n do
for j:=max downto 1 do
if g[i]<=j
then
a[j]:=Maxim(a[j], a[j-g[i]]+c[i]);
writeln(a[max]);
close(input);
close(output);
end.