Pagini recente » Cod sursa (job #2973901) | Cod sursa (job #457297) | Cod sursa (job #2539523) | Cod sursa (job #2563097) | Cod sursa (job #423212)
Cod sursa(job #423212)
const M=(1 shl 14);
var i,j,gen,min,w:longint;
e,c:array[1..10000] of longint;
v:array [1..M] of longint;
f,g:text;
begin
assign(f,'energii.in');
assign(g,'energii.out');
reset(f);
rewrite(g);
readln(f,gen);
readln(f,w);
for i:=1 to gen do
readln(f,e[i],c[i]);
for i:=1 to gen do
begin
for j:=w downto 1 do
if (v[j]<>0) and ((v[j]+c[i]<v[j+e[i]])or(v[j+e[i]]=0)) then
v[j+e[i]]:=v[j]+c[i];
if (c[i]<v[e[i]]) or (v[e[i]]=0) then
v[e[i]]:=c[i];
end;
min:=maxlongint;
for i:=w to M do
if (v[i]<>0) and (v[i]<min) then
min:=v[i];
if min=maxlongint then writeln(-1)
else writeln(g,min);
close(g);
end.