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<long long, long long>> art(n);
vector<long long> a(n);
long long ans = 0;
for(int i = 0; i < n; i++){
cin >> art[i].first >> art[i].second;
}
sort(art.begin(), art.end());
a[n - 1] = art[n - 1].second;
ans = a[n - 1];
for (int i = n - 2; i >= 0; i--) {
a[i] = max(art[i].second + (a[i+1] - art[i+1].first + art[i].first), art[i].second);
ans = max(ans, a[i]);
}
cout << ans << endl;
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... |