Pagini recente » Cod sursa (job #2478398) | Cod sursa (job #2838103) | Cod sursa (job #555970) | Cod sursa (job #995297) | Cod sursa (job #148559)
Cod sursa(job #148559)
var f,h:text;
c,e:array[1..1000] of word;
v:array[0..5000] of longint;
i,j,g,w:integer;
begin
assign(f,'energii.in'); reset(f);
assign(h,'energii.out'); rewrite(h);
readln(f,g);
readln(f,w);
for i:=1 to g do
readln(f,e[i],c[i]);
v[0]:=0;
for i:=1 to w do
v[i]:=maxint;
for i:=w downto 0 do
if v[i]<>maxint then
for j:=1 to g do
if i+e[j]>w then
v[w]:=v[w]+c[j]
else if v[i+e[j]]>v[i]+c[j] then
v[i+e[j]]:=v[i]+c[j];
if (v[w]<>maxint) then
write(h,v[w])
else write(h,-1);
close(f); close(h);
end.