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() {
long long n;
cin >> n;
vector<pair<long long, long long> > arr;
for (long long i=0; i<n; i++) {
long long sz, va;
cin >> sz >> va;
arr.push_back(make_pair(sz, va));
}
sort(arr.begin(), arr.end());
long long best = 0;
priority_queue<long long> pick;
pick.push(arr[0].first);
long long sz[n], vl[n];
for (long long i=0; i<n; i++) sz[i] = arr[i].first;
for (long long i=0; i<n; i++) vl[i] = arr[i].second;
long long pf[n];
pf[0] = arr[0].second;
for (long long i=1; i<n; i++) pf[i] = pf[i-1] + vl[i];
for (long long right=0; right<n; right++) {
long long cons = pf[right] - sz[right];
// maximise the other
if (right > 0) {
pick.push(-pf[right-1]+sz[right]);
}
best = max(best, cons + pick.top());
}
cout << best << 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... |