Cod sursa(job #929338)

Utilizator TrifanTTrifan TrifanT Data 26 martie 2013 23:13:39
Problema Problema rucsacului Scor 10
Compilator fpc Status done
Runda Arhiva educationala Marime 0.63 kb
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.