Pagini recente » Cod sursa (job #2052853) | Monitorul de evaluare | Cod sursa (job #2753845) | Cod sursa (job #1260294) | Cod sursa (job #71212)
Cod sursa(job #71212)
const lmax=10001;
var a,b:array[1..lmax]of longint;
t,min,g,w,e,c,i,j:longint;
begin
assign(input,'energii.in');
reset(input);
//fillchar(a,sizeof(a),0);
for t:=1 to lmax do
a[i]:=-1;
readln(g,w);
readln(e,c);
a[e]:=c;
for i:=2 to g do
begin
// fillchar(b,sizeof(b),0);
for t:=1 to lmax do
b[i]:=-1;
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.