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 <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct Artwork {
long long size;
int value;
bool operator < (const Artwork& other) const {
return size < other.size;
}
};
int main()
{
int n;
cin >> n;
vector < Artwork > gallery(n + 1);
for (int i = 1; i <= n; ++i) {
cin >> gallery[i].size >> gallery[i].value;
}
sort(gallery.begin() + 1, gallery.end());
vector < long long > valuePartialSums(n + 1);
for (int i = 1; i <= n; ++i) {
valuePartialSums[i] = valuePartialSums[i - 1] + gallery[i].value;
}
vector < long long > suffixMax(n + 2);
for (int i = n; i > 0; --i) {
suffixMax[i] = max(suffixMax[i + 1], valuePartialSums[i] - gallery[i].size);
}
long long ans = 0LL;
for (int i = 1; i <= n; ++i) {
ans = max(ans, suffixMax[i] + gallery[i].size - valuePartialSums[i - 1]);
}
cout << ans << '\n';
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... |