Pagini recente » Cod sursa (job #2058080) | Cod sursa (job #822857) | Cod sursa (job #1930241) | Cod sursa (job #894474) | Cod sursa (job #146872)
Cod sursa(job #146872)
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.