Cod sursa(job #929342)

Utilizator TrifanTTrifan TrifanT Data 26 martie 2013 23:16:53
Problema Problema rucsacului Scor 80
Compilator fpc Status done
Runda Arhiva educationala Marime 0.65 kb
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:=gmax downto 1 do if g[i]<=j then a[j]:=max;{ tr; }
                     end;
 writeln(a[gmax]);

 close(input);
 close(output);
end.