Pagini recente » Cod sursa (job #2226852) | Cod sursa (job #1731892) | Cod sursa (job #1396321) | Cod sursa (job #904792) | Cod sursa (job #146869)
Cod sursa(job #146869)
var n,w,x,y,m,i,j:longint;
a:array[1..6005] of longint;
f,g:text;
begin
assign(f,'energii.in');reset(f);
assign(g,'energii.out');rewrite(g);
readln(f,n,w);
m:=maxlongint;
for i:=1 to n do begin
read(f,x,y);
if (x>=w) then begin
if y<m then m:=y;
end
else begin
for j:=(m-x) downto m do
if a[j]+y>m then m:=a[j]+y;
end;
end;
if m<>maxlongint then writeln(g,m)
else writeln(g,'-1');
close(f);
close(g);
end.