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<array<long, 2>> v(n);
for (auto &[a, b] : v) cin >> a >> b;
sort(v.begin(), v.end());
vector<long> pref(n + 1, 0);
for (int i = 0; i < n; i++)
pref[i + 1] = pref[i] + v[i][1];
vector diff(pref.begin() + 1, pref.end());
for (int i = 0; i < n; i++)
diff[i] -= v[i][0];
long res = 0;
long cur = LONG_MIN / 2;
for (int i = n - 1; i >= 0; i--)
{
cur = max(cur, diff[i]);
res = max(res, cur + v[i][0] - pref[i]);
}
cout << res << '\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... |