Pagini recente » Cod sursa (job #2348475) | Cod sursa (job #43227) | Cod sursa (job #933758) | Cod sursa (job #23516) | Cod sursa (job #59134)
Cod sursa(job #59134)
program energii;
var en,c,c1:array[0..1001] of word;
s:array[0..1001] of boolean;
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;
s[0]:=false;
c1[0]:=0;
cost:=maxint;
assign(f,'energii.out'); rewrite(f);
for i:=1 to g do
for j:=vmax downto 0 do
if not (s[j]) then
begin
if s[j+en[i]] then
begin
if j+en[i]>vmax then vmax:=j+en[i];
s[j+en[i]]:=false;
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=maxint then writeln(f,'-1')
else writeln(f,cost);
close(f);
end.