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 ll long long
const int N = 5e5+5;
ll n, sum, ans = -1e18, mx;
pair<ll,ll> a[N];
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i].first >> a[i].second;
}
sort(a + 1, a + n + 1);
mx = -a[1].first;
for(int i = 1; i <= n; i++){
sum += a[i].second;
ans = max(ans, (sum - a[i].first) - mx);
mx = min(mx, sum - a[i+1].first);
}
cout << ans << endl;
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... |