Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- int main()
- {
- _test
- {
- int n;
- cin>>n;
- vector<pair<ll int, ll int>> vp(n);
- for(auto &[l, r]: vp) cin>>l>>r;
- ll int ans=1e9, low=0, high=1e9, mid;
- auto poss = [&](int k)
- {
- ll int x=0, y=0;
- for(auto [a, b]: vp)
- {
- x -= k;
- y += k;
- x = max(x, a);
- y = min(y, b);
- if(x > y) return false;
- }
- return true;
- };
- while(low <= high)
- {
- int mid = (low + high)/2;
- if(poss(mid)) ans=mid, high=mid-1;
- else low=mid+1;
- }
- cout<<ans<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment