Pagini recente » Cod sursa (job #1347247) | Cod sursa (job #2751249) | Monitorul de evaluare | Cod sursa (job #2242933) | Cod sursa (job #148638)
Cod sursa(job #148638)
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]:=maxlongint;
for j:=1 to g do
for i:=w downto 0 do
if v[i]<>maxint then
if (i+e[j]>w) and (v[w]=maxint) 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.