Cod sursa(job #848283)

Utilizator t.g.g.tt.g.g.t t.g.g.t Data 5 ianuarie 2013 11:34:48
Problema Energii Scor 35
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.78 kb
var n:integer; a:array[0..1000,0..10000]of longint; b:array[1..2,1..1000]of integer;
i,j,g,min,j2,j3:integer;
begin
assign(input,'energii.in'); reset(input);
readln(n,g);
for i:=1 to n do readln(b[2,i],b[1,i]);
for i:=1 to n do
  for j:=1 to 10000 do
    begin
      if j=b[2,i] then begin if (a[i-1,j]>b[1,i]) or (a[i-1,j]=0) then a[i,j]:=b[1,i] else a[i,j]:=a[i-1,j]; end
      else if j<b[2,i] then a[i,j]:=a[i-1,j] else if a[i-1,j-b[2,i]]>0 then begin if ((a[i-1,j-b[2,i]]+b[1,i])<a[i-1,j]) or (a[i-1,j]=0) then a[i,j]:=a[i-1,j-b[2,i]]+b[1,i] else a[i,j]:=a[i-1,j] end else a[i,j]:=a[i-1,j];
    end;
assign(output,'energii.out'); rewrite(output);
for i:=g to 10000 do if a[n,i]<>0 then if min=0 then min:=a[n,i] else if a[n,i]<min then min:=a[n,i];
writeln(min);
close(output);
end.