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;
typedef long long ll;
typedef pair<int, int> ii;
const int maxn = 5e5 + 10;
ll a[maxn], p[maxn];
int main(int argc, char const *argv[]) {
#ifdef LOCAL_TESTING
freopen("in", "r", stdin);
#endif
int n; cin >> n;
vector<pair<ll, ll> > x(n);
for(int i = 0; i < n; i++) {
cin >> x[i].first >> x[i].second;
}
sort(x.begin(), x.end());
for(int i = 0; i < n; i++) {
a[i] = x[i].first;
}
p[0] = x[0].second;
for(int i = 1; i < n; i++)
p[i] = p[i - 1] + x[i].second;
// p[i] - p[j - 1] - a[i] + a[j]
//=p[i] - a[i] + (a[j] - p[j - 1])
ll ans = p[0] - a[0], Max = a[0];
for(int i = 1; i < n; i++) {
Max = max(Max, a[i] - p[i - 1]);
ans = max(ans, p[i] - a[i] + Max);
}
cout << ans << endl;
}
# | 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... |