This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define ff first
#define ss second
const int maxn = 5e5 + 5, INF = 0x3f3f3f3f3f3f3f3f;
pii v[maxn];
int32_t main(){
int n; cin >> n;
for(int i = 0; i < n; i++) cin >> v[i].ff >> v[i].ss;
sort(v, v+n);
int sum = 0, mn = INF, ans = 0;
for(int i = 0; i < n; i++){
sum += v[i].ss;
if(i) ans = max(ans, sum - (v[i].ff - mn));
mn = min(mn, sum-v[i].ss+v[i].ff);
}
cout << ans << '\n';
}
# | 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... |