Cod sursa(job #147563)

Utilizator Tase_CCapalna Tanase Tase_C Data 3 martie 2008 10:38:35
Problema Energii Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.6 kb
const max=100000000;
var n,w,x,y,m,i,j,f,g:longint;
a:array[0..6001] of longint;
begin
assign(input,'energii.in');reset(input);
assign(output,'energii.out');rewrite(output);
readln(f,n,w);
for i:=1 to w do
a[i]:=max;
m:=max;
for i:=1 to n do begin
read(f,x,y);
if (x>=w) then begin
if y<m then m:=y;
end
          else begin
          for j:=w-x to w do
          if a[j]+y<m then m:=a[j]+y;
          for j:=w downto x do
          if a[j-x]+y<a[j] then a[j]:=a[j-x]+y;
                 end;
end;
if m<>max then writeln(g,m)
          else writeln(g,'-1');
close(input);
close(output);
end.