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;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
pair<long long, long long> a[n+1];
a[0] = {-1e18, -1e9};
for (int i = 1; i <= n; ++i) {
cin >> a[i].first >> a[i].second;
}
sort(a, a+n+1);
long long pref[n+1]; pref[0] = 0;
for (int i = 1; i <= n; ++i) pref[i] = pref[i-1]+a[i].second;
long long ans = a[n].second;
long long s = 0;
for (int i = 1; i <= n; ++i) {
ans = max(ans, (pref[i]-a[i].first)+s);
s = max(s, a[i].first-pref[i-1]);
}
cout << ans << '\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... |