/**
* author: MINHTPC
*
**/
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin() , a.end()
#define FOR(i ,a , b) for(int i = a ; i <= b ; ++i)
#define bit(mask,i) ((mask>>i)&1)
#define name "task"
#define lo lower_bound
#define up upper_bound
#define count_bit1(x) __builtin_popcountll(x)
#define count_bit01(x) __builtin_clzll(x)
#define count_bit10(x) __builtin_ctzll(x)
using namespace std;
const int N=5e5+5;
const long long INF=-1e18;
using pii=pair<ll,ll>;
pii a[N];
long long f[N];
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;
sort(a+1,a+n+1);
for(int i=1;i<=n;i++) f[i]=f[i-1]+a[i].se;
long long mx=INF,ans=INF;
for(int i=1;i<=n;i++) {
mx=max(mx,a[i].fi-f[i-1]);
ans=max(ans,mx+f[i]-a[i].fi);
}
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... |