#include <bits/stdc++.h>
#define el cout << '\n'
#define fi first
#define se second
#define ll long long
#define pb push_back
#define num(_a) (_a-'0')
#define sz(__v) (int)(__v).size()
using namespace std;
template <typename T>
void debug_out(const T& value) {
    cerr << value << endl;
}
template <typename T, typename... Args>
void debug_out(const T& first, const Args&... args) {
    cerr << first << ", ";
    debug_out(args...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
const int mod = (int)1e9 + 7;
template<class T> bool minimize(T& cur, const T& val) { return val < cur ? cur = val, 1 : 0; }
template<class T> bool maximize(T& cur, const T& val) { return val > cur ? cur = val, 1 : 0; }
using namespace std;
const int maxn = (long long)1e6;
#define pii pair<int,int>
pii a[maxn + 5];
bool cmp(pii &a, pii &b){
 if(a.fi == b.fi){
    return a.se < b.se;
   }
   return a.fi < b.fi;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i].fi >> a[i].se;
    }
    ll ans = 0;
     sort(a + 1, a + n + 1, cmp);
     ll sum = a[1].se;
    for(int i = 2; i <= n; i++){
         sum += a[i].se;
        if(ans < sum - (a[i].fi - a[1].fi)){
            ans = sum - (a[i].fi - a[1].fi);
        }
        else sum -= a[i].se;
     }
     cout << ans;
}
| # | 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... |