# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
557248 | Ai7081 | Art Exhibition (JOI18_art) | C++17 | 96 ms | 10764 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;
#define ll long long
#define st first
#define nd second
const int N = 2e5+5;
ll n, sum[N], max_dp, ans;
pair<ll, ll> p[N];
int main() {
scanf(" %lld", &n);
for (int i=1; i<=n; i++) {
scanf(" %lld %lld", &p[i].st, &p[i].nd);
}
sort(p+1, p+1+n);
for (int i=1; i<=n; i++) sum[i] = sum[i-1] + p[i].nd;
max_dp = p[1].st - sum[0];
for (int i=1; i<=n; i++) {
ans = max(ans, sum[i] - p[i].st + max_dp);
if (i<n) max_dp = max(max_dp, p[i+1].st - sum[i]);
}
printf("%lld", 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... |