Pagini recente » Cod sursa (job #1157332) | Cod sursa (job #2410368) | Cod sursa (job #2418434) | Cod sursa (job #1810284) | Cod sursa (job #167781)
Cod sursa(job #167781)
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.