# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
625343 | 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());
long long s = 0;
long long curMin = v[0].first;
long long best = 0;
int ind;
for(int i = 0; i < n; i++)
{
s += v[i].second;
long long cur = s + curMin - v[i].first;
if(best <= cur)
{
best = s + curMin - v[i].first;
ind = i;
}
}
long long answer = best;
s = v[0].second;
for(int i = 1; i <= ind; i++)
{
answer = max(answer, best - s + v[i].first - curMin);
s += v[i].second;
}
printf("%lld\n", answer);
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... |