//I love ManchesterUnited
#include<bits/stdc++.h>
using namespace std;
#define love ManchesterUnited
#define int long long
#define pb push_back
#define FOR(i,a,b) for (int i=(a); i<=(b); i++)
#define FORD(i,b,a) for (int i=(b); i>=(a); i--)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define RED(i, n) for(int i=(n)-1; i>=0; --i)
#define time() cerr << endl << "-------------Time:" << 1000.0 * clock() / CLOCKS_PER_SEC << "ms.";
#define ALL(a) (a).begin(),(a).end()
#define ii pair<int,int>
#define iii pair<int,ii>
#define fi first
#define se second
#define endl '\n'
#define MASK(x) (1 << (x))
#define BIT(mask,i) ((mask >> i) & 1)
typedef long long ll;
const int N = 1e6 + 5;
const int INF = 1e18;
const int MOD = 1e9 + 7;
int n;
ii a[N];
int pre[N];
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
FOR(i,1,n) cin >> a[i].fi >> a[i].se;
sort(a + 1, a + n + 1);
FOR(i,1,n) pre[i] = pre[i - 1] + a[i].se;
int ans = -INF;
int mn = INF;
FOR(i,1,n){
if (i >= 2) ans = max(ans, (pre[i] - a[i].fi) - mn);
mn = min(mn, pre[i - 1] - a[i].fi);
}
cout << ans << endl;
}
# | 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... |