이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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(), 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... |