Pagini recente » Cod sursa (job #1924694) | Cod sursa (job #2670336) | Cod sursa (job #3209450) | Cod sursa (job #1341711) | Cod sursa (job #59138)
Cod sursa(job #59138)
program energii;
var en,c:array[0..1001] of word;
s:array[0..10001] of boolean;
c1:array[0..10001] of word;
g,n,i,j,w,vmax,cost:word;
f:text;
begin
assign(f,'energii.in'); reset(f);
readln(f,g); readln(f,w);
for i:= 1 to g do
readln(f,en[i],c[i]);
close(f);
vmax:=0;
for i:= 1 to 10001 do s[i]:=false;
s[0]:=true;
c1[0]:=0;
cost:=65000;
assign(f,'energii.out'); rewrite(f);
for i:=1 to g do
for j:=vmax downto 0 do
if (s[j]) then
begin
if not(s[j+en[i]]) then
begin
if j+en[i]>vmax then vmax:=j+en[i];
s[j+en[i]]:=true;
c1[j+en[i]]:=c1[j]+c[i];
end
else
if c1[j+en[i]]<c1[j]+c[i] then
c1[j+en[i]]:=c1[j]+c[i];
if j+en[i]>=w then if cost>c1[j+en[i]] then cost:=c1[j+en[i]];
end;
if cost=65000 then writeln(f,'-1')
else writeln(f,cost);
close(f);
end.