最大值
while l<=r do 左开右开
mid:=(l+r) div 2;
if ok then l:=mid+1 ans:=mid
else r:=mid-1
ans:=r;
inc(r) X
while l<r do 左闭右开
mid:=(l+r) div 2
if ok then l:=mid
else r:=mid
ans:=l
inc(r)左开右开
while l<r do
mid:=(l+r) div 2
if ok then l:=mid+1//ans:=mid
else r:=mid
ans:=l-1 or r-1 //ans
while l<r do 左闭右不确定 直到左右相等
mid:=(l+r+1) div 2
if ok then l:=mid
else r:=mid-1
l r
最小
while l<r do 左不确定右闭
mid:=(l+r) div 2
if ok then r:=mid
else l:=mid+1
l r
while(l<=r){
int mid=l+r>>1;
for(i=f=1;i<=n && f<=m;i++,f++) while(f<=m && abs(a[i]-b[f])+abs(b[f])>mid) f++;
if(i==n+1 && f<=m+1) ans=mid,r=mid-1;
else l=mid+1;
ans l
while (l<r) do begin
m:=(l+r) div 2;
s:=a[0]; u:=0;
for i:=1 to n do
if (a[i]-s>=m) then s:=a[i] else inc(u);
if (u>p) then r:=m-1 else begin l:=m+1;ans:=m;end;
end;
repeat mid:=(l+r) div 2;s:=0;f:=0; for i:=l to mid do begin inc(sum[b[i].s],b[i].d);dec(sum[b[i].t+1],b[i].d); end; for i:=1 to n do begin inc(s,sum[i]); if s>rr[i] then begin f:=-1;break;end; end; if f=-1 then begin r:=mid; for i:=l to mid do begin dec(sum[b[i].s],b[i].d);inc(sum[b[i].t+1],b[i].d); end; end else l:=mid+1; until l=r; if l=m+1 then writeln(0) else begin writeln(-1); writeln(l); end;