#include<bits/stdc++.h>
#define ll long long
const int nmax = 5e5 + 5, N = 4e5;
const ll oo = 1e18;
const int lg = 18, M = 4e3;
const int base = 2e5, mod = 1e9 + 7;
#define pii pair<int, int>
#define fi first
#define se second
#define endl "\n"
#define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' ';cout << endl
using namespace std;
int n;
pii a[nmax];
ll s[nmax], pre[nmax];
main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen("code.inp", "r", stdin);
// freopen("code.out", "w", stdout);
cin >> n;
for(int i = 1; i <= n; ++i) cin >> a[i].fi >> a[i].se;
sort(a +1 , a + 1 + n);
pre[0] = -oo;
ll ans = -oo;
for(int i = 1; i <= n; ++i){
s[i] = s[i - 1] + a[i].se;
pre[i] = max(pre[i - 1], -s[i - 1] + a[i].fi);
ans = max(ans, s[i] - a[i].fi + pre[i]);
}
cout << ans;
}
/*
1_t1 + 1
*/
Compilation message
art.cpp:18:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
18 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |