# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
672138 | Stavab | Art Exhibition (JOI18_art) | C++14 | 0 ms | 212 KiB |
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 <vector>
#include <utility>
#include <algorithm>
using namespace std;
int main()
{
int n;
scanf("%d", &n);
vector<pair<long long, long long>> v(n);
for(int i = 0; i < n; i++)
{
scanf("%lld", &v[i].first);
scanf("%lld", &v[i].second);
}
sort(v.begin(), v.end());
vector<long long> sums(n + 1);
sums[0] = 0;
for(int i = 0; i < n; i++)
sums[i + 1] = sums[i] + v[i].second;
long long best = 0;
long long curMax = -9999999999999999;
for(int i = n - 1; i >= 0; i--)
{
curMax = max(curMax, sums[i + 1] - v[i].first);
if(i == 0)
best = max(best, curMax + v[i].first);
else
best = max(best, curMax - sums[i] + v[i].first - v[i - 1].first);
}
printf("%lld\n", best);
return 0;
}
Compilation message (stderr)
# | 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... |