Cod sursa(job #704493)

Utilizator andrei_toaderToader Andrei Sorin andrei_toader Data 2 martie 2012 18:24:18
Problema Problema rucsacului Scor 80
Compilator fpc Status done
Runda Arhiva educationala Marime 0.6 kb
program rucscac;
type natural=record
 gr,c:integer;
end;
var v:array[1..5000] of natural;
    c:array[0..1,0..10000] of longint;
    n,greutate,j,l,i:integer;
    f,g:text;

begin
 assign (f,'rucsac.in'); reset (F);
 assign (g,'rucsac.out'); rewrite (g);
 readln (f,n,greutate);
 for i:=1 to n do
  readln (f,v[i].gr,v[i].c);
 l:=0;
 for i:=1 to n do
 begin
  for j:=1 to greutate do
  begin
  c[1-l,j]:=c[l,j];
  if v[i].gr<=j then
   if v[i].c+c[l,j-v[i].gr]>c[1-l,j] then
    c[1-l,j]:=v[i].c+c[l,j-v[i].gr];
   end;
  l:=1-l;
 end;
 write (g,c[l,greutate]);
 close (f); close (G);
end.