#include <bits/stdc++.h>
using namespace std;
#define int long long
using ii = pair<int, int>;
const int N = 5e5 + 5;
int n;
ii c[N];
int32_t main(){
cin.tie(0)->sync_with_stdio(0);
// #define task "test"
// if(fopen(task ".inp", "r")){
// freopen(task ".inp", "r", stdin);
// freopen(task ".out", "w", stdout);
// }
cin >> n;
for(int i = 1; i <= n; i++) cin >> c[i].first >> c[i].second;
sort(c + 1, c + n + 1);
for(int i = 1; i <= n; i++) c[i].second += c[i - 1].second;
int mx = 0, res = 0;
for(int i = 1; i <= n; i++){
mx = max(mx, c[i].first - c[i - 1].second);
res = max(res, c[i].second - c[i].first + mx);
}
cout << res << "\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... |