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(){
int n; cin >> n;
vector<pair<int, int>> a(n);
for (auto p : a) cin >> p.first >> p.second;
sort(a.begin(), a.end());
int pref[n + 1];
for (int i = 0; i < n; i++) pref[i + 1] = pref[i] + a[i].second;
vector diff(pref + 1, pref + n + 1);
for (int i = 0; i < n; i++) diff[i] -= a[i].first;
int ans = 0, tmp = INT_MIN / 2;
for (int i = n - 1; i > -1; i--)
{
tmp = max(tmp, diff[i]); ans = max(ans, tmp + a[i].first - pref[i]);
}
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... |