#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL); using ll = int64_t; /*-----------------------------------------------------------------------------------------------------*/
boolcheck(ll x, vector<pair<ll, ll>> &arr){ ll nd = 0, cur = 0; int n = arr.size(); for(int i = 0; i < n; i++) { if(arr[i].second > x) { ll w = min(nd, arr[i].second - x); nd -= w; cur += arr[i].second - w - x; } else { ll owo = x - arr[i].second; ll w = min(cur, owo); cur -= w; nd += owo - w; } if(i < n - 1) { cur = max<ll>(0, cur - (arr[i + 1].first - arr[i].first)); if(nd) nd += arr[i + 1].first - arr[i].first; } } return (!nd); }
signedmain(){ EmiliaMyWife int n; while(cin >> n) { vector<pair<ll, ll>> arr(n); for(int i = 0; i < n; i++) cin >> arr[i].first >> arr[i].second; ll l = 0, r = 2e12; while(l < r) { ll m = l + r >> 1; if(!check(m, arr)) r = m; else l = m + 1; } cout << l - 1 << '\n'; }