#include<bits/stdc++.h>
using namespace std;
const int N = 5*1e5+1;
struct Art{
long long a;
int b;
}v[N];
long long pre[N];
bool cmp(const Art& x, const Art& y){
return x.a < y.a;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n; cin>>n;
for(int i = 1; i <= n; ++i)cin>>v[i].a>>v[i].b;
sort(v+1, v+n+1, cmp);
memset(pre,0,N);
for(int i = 1; i <= n; ++i)pre[i + 1] = pre[i] + v[i].b;
long long ans = -2e18, max_i = -2e18;
for(int j = 1; j <= n; ++j){
long long val_i = v[j].a - pre[j];
max_i = max(max_i, val_i);
long long val_j = pre[j + 1] - v[j].a;
ans = max(ans, max_i + val_j);
}
cout<<ans<<'\n';
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... |