#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define REP(i,r) for(ll i=0,_r=(r);i<_r;i++)
#define FOR(i,l,r) for(ll i=(l),_r=(r);i<=_r;i++)
#define FORE(i,v) for(__typeof((v).begin()) i=(v).begin();i!=(v).end();i++)
#define FORNG(i,r,l) for(ll i=(r),_l=(l);i>=_l;i--)
#define MASK(i) (1LL<<(i))
#define BIT(x,i) (((x)>>(i))&1LL)
#define all(v) (v).begin(),(v).end()
#define size(v) ((ll)(v).size())
const ll MOD = 1e9+7, N = 2e5+10, INF = 1e18, LOG = 20;
int main(){
//freopen(".INP", "r", stdin);
//freopen(".OUT", "w", stdout);
ios_base::sync_with_stdio(0);cin.tie(0);
ll n;cin>>n;
vector<pair<ll,ll>> d(n + 1, {-INF, 0});
ll ans = 0;
FOR(i,1,n)cin>>d[i].fi>>d[i].se,ans = max(ans, d[i].se);
sort(all(d));
FOR(i,1,n)d[i].se += d[i - 1].se;
ll ma = -INF;
FOR(i,1,n){
ma = max(ma, - d[i - 1].se + d[i].fi);
ans = max(ans, - d[i].fi + d[i].se + ma);
}
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... |