D. Jumping Through Segments
输入数据
4
5
1 5
3 4
5 6
8 10
0 1
3
0 2
0 1
0 3
3
3 8
10 18
6 11
4
10 20
0 5
15 17
2 2
输出范围
7 0 5 13
#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<char,int>PII;
const int N=2e5+10;
int l[N],r[N];
int n;
bool check(int k)
{
int L=0,R=0;
for(int i=1;i<=n;i++)
{
int LL=L-k,RR=R+k;
if(LL>r[i]||RR<l[i]) return false;
L=max(LL,l[i]);
R=min(RR,r[i]);
}
return true;
}
signed main()
{
int t;cin>>t;
while(t--)
{
cin>>n;
for(int i=1;i<=n;i++) cin>>l[i]>>r[i];
int l=0,r=1e9+10;
while(l<r)
{
int mid=(l+r)>>1;
if(check(mid)) r=mid;
else l=mid+1;
}
cout<<l<<endl;
}
return 0;
}