Pagini recente » Cod sursa (job #2496572) | Cod sursa (job #2295055) | Cod sursa (job #1708208) | Cod sursa (job #2311743) | Cod sursa (job #148570)
Cod sursa(job #148570)
var f,h:text;
c,e:array[1..1000] of integer;
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) and (v[w]=maxint) then
begin
v[w]:=v[w]+c[j];
break;
end
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.