#include<bits/stdc++.h>
#define endl "\n"
#define int long long int
#define pb push_back
#define mp make_pair
#define Bound 2e5 + 1
#define mid (l+r+1)/2
using namespace std;
void solve() {
    int n;
    cin >> n;
    int pre = 0;
    int mn = 1e18+5;
    int ans = 0;
    array<int,2>* arr = new array<int,2>[n];
    for(int i = 0; i < n; i++) cin >> arr[i][0] >> arr[i][1];
    sort(arr, arr+n);
    for(int i = 0; i < n; i++) {
        mn = min(mn, pre-arr[i][0]); //If get a smaller mn, restart the exhibition form i
        //difference = arr[i][0] - mn
        pre = pre + arr[i][1]; //total point
        ans = max(ans, pre - arr[i][0] - mn); //total point - difference
    }
    cout << ans;
}
int32_t main() {
    cin.tie(0); cout.tie(0);
    //ios::sync_with_stdio(false);
    
    int t = 1; //cin >> t;
    while(t--) solve();
    return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |