# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
210031 | SamAnd | Art Exhibition (JOI18_art) | C++17 | 306 ms | 24740 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 <bits/stdc++.h>
using namespace std;
const int N = 500005;
struct ban
{
long long a;
int b;
};
bool operator<(const ban& a, const ban& b)
{
return a.a < b.a;
}
int n;
ban a[N];
long long p[N];
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
scanf("%lld%d", &a[i].a, &a[i].b);
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; ++i)
p[i] = p[i - 1] + a[i].b;
long long maxu = -p[1 - 1] + a[1].a;
long long ans = a[1].b;
for (int i = 2; i <= n; ++i)
{
maxu = max(maxu, -p[i - 1] + a[i].a);
ans = max(ans, p[i] - a[i].a + maxu);
}
printf("%lld\n", ans);
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... |