#include <bits/stdc++.h>
using namespace std;
#define N 500005
#define ll long long int
#define sz(x) (int)x.size()
#define ff first
#define ss second
ll T, n, f[N], mx[N];
pair <ll,ll> a[N];
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin >> n;
ll s = 0;
for(int i = 1; i <= n; i++){
cin >> a[i].ff >> a[i].ss;
s += a[i].ss;
}
sort(a+1,a+n+1);
for(int i = n; i >= 1; i--){
f[i] = f[i+1] - a[i].ss;
mx[i] = max(mx[i+1], f[i] + (a[n].ff - a[i-1].ff));
}
ll ans = mx[1], x = 0;
for(int i = 1; i <= n; i++){
x += a[i].ss;
ans = max(ans,mx[i+1] + a[i].ff - x);
}
ans += (s - (a[n].ff - a[1].ff));
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |