Cod sursa(job #1174517)

Utilizator azkabancont-vechi azkaban Data 23 aprilie 2014 07:47:05
Problema Problema rucsacului Scor 100
Compilator fpc Status done
Runda Arhiva educationala Marime 0.56 kb
Program dinam;
var i,j,n,m,a,b,Pmax : longint;
    G : array[1..10000] of longint;
begin
   assign(input,'rucsac.in'); reset(input);
   assign(output,'rucsac.out'); rewrite(output);
   readln(n,m);
   Pmax:=0;
   for i:=1 to n do begin
                         readln(a,b);
                         for j:=m downto a do
                                            if G[j-a]+b>G[j] then G[j]:=G[j-a]+b;
                    end;
   for i:=m downto 1 do
            if G[i]>Pmax then Pmax:=G[i];
   writeln(Pmax);
   close(input);
   close(output);
end.