This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// source: https://oj.uz/problem/view/JOI18_art
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
const int mxN = 500000;
int n;
ll pre[mxN], suf[mxN];
pair<ll, ll> a[mxN];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 0; i < n; ++i)
cin >> a[i].first >> a[i].second;
sort(a, a + n);
for (int i = 1; i < n; ++i)
pre[i] = suf[i] = pre[i - 1] + a[i].second - (a[i].first - a[i - 1].first);
for (int i = n - 2; ~i; --i)
suf[i] = max(suf[i], suf[i + 1]);
ll ans = 0;
for (int i = 0; i < n; ++i)
ans = max(ans, suf[i] - pre[i] + a[i].second);
cout << ans;
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... |