Cod sursa(job #2391915)

Utilizator lazari.dDana Vik lazari.d Data 29 martie 2019 12:53:52
Problema Problema rucsacului Scor 10
Compilator fpc Status done
Runda Arhiva educationala Marime 0.67 kb
uses math;
var n,i,j,g,ct,maxx:integer;
    fi,fo:text;
    u:boolean;
    m:array[0..10000] of integer;
    p:array[0..5000] of integer;
    w:array[0..5000] of integer;
begin
   assign(fi,'rucsac.in');
   reset(fi);
   assign(fo,'rucsac.out');
   rewrite(fo);
   read(fi,n);
   readln(fi,g);
   for i:=1 to n do begin
                    read(fi,w[i]);
                    read(fi,p[i]);
                    readln(fi);
                    end;
  for j:=0 to g do
               m[0]:=0;
  for i:=1 to n do
                for j:=g downto w[i] do
                        m[j]:=max(m[j],m[j-w[i]]+p[i]);
  writeln(fo, m[g]);

 close(fi);
 close(fo);
 end.