Pagini recente » Cod sursa (job #2627725) | Cod sursa (job #2941796) | Cod sursa (job #3032947) | Cod sursa (job #2368547) | Cod sursa (job #71208)
Cod sursa(job #71208)
const lmax=12000;
var a,b:array[1..lmax]of longint;
min,g,w,e,c,i,j:longint;
begin
assign(input,'energii.in');
reset(input);
fillchar(a,sizeof(a),0);
readln(g,w);
readln(e,c);
a[e]:=c;
for i:=2 to g do begin
fillchar(b,sizeof(b),0);
readln(e,c);
for j:=1 to lmax-e do
if(a[j]<>0)then
b[j+e]:=a[j]+c;
for j:=1 to lmax do
if(a[j]<>0)and(a[j]<b[j])or(b[j]=0) then b[j]:=a[j];
if(c<b[e])or(b[e]=0) then b[e]:=c;
a:=b;
end;
min:=maxlongint;
for i:=w to lmax do
if (a[i]<>0)and(a[i]<min) then min:=a[i];
close(input);
assign(output,'energii.out');
rewrite(output);
if min<>maxlongint then
writeln(min)
else
writeln(-1);
close(output);
end.