Cod sursa(job #167781)

Utilizator DanielGGlodeanu Ioan Daniel DanielG Data 30 martie 2008 01:39:05
Problema Energii Scor 100
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.64 kb
var e,c:array[1..1005] of integer;
v:array[1..6001] of longint;
aux:real;
auxx,n,w,ww,i,j:integer;
cost:longint;
f:text;
begin
assign(f,'energii.in');reset(F);
readln(f,n);
readln(f,w);
for i:=1 to n do
readln(f,e[i],c[i]);
close(f);
for i:=1 to w do v[i]:=100000000;
cost:=100000000;
for i:=1 to n do
if (e[i]>=w) then
begin
if c[i]<cost then cost:=c[i]
end
else
begin
for j:=w-e[i] to w do
if v[j]+c[i]<cost then cost:=v[j]+c[i];
for j:=w downto e[i] do
if v[j-e[i]]+c[i]<v[j] then v[j]:=v[j-e[i]]+c[i];
end;
assign(f,'energii.out');rewrite(f);
if cost<>100000000 then write(f,cost)
else write(f,'-1');
close(f);
end.