| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1283005 | anhphant | Art Exhibition (JOI18_art) | C++20 | 155 ms | 16076 KiB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fi first
#define se second
ll N;
pair<ll, ll> A[500007];
int main() {
ios_base :: sync_with_stdio(0);
cin.tie(0); cout.tie(0); cerr.tie(0);
if (fopen("test.inp", "r")) {
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
cin >> N;
for(int i = 1; i <= N; ++i) {
cin >> A[i].fi >> A[i].se;
}
sort(A + 1, A + 1 + N);
vector<ll> diff(N + 7, 0LL);
diff[1] = A[1].se - A[1].fi;
for(int i = 2; i <= N; ++i) {
diff[i] = (A[i].se + A[i - 1].se - A[i].fi) - (A[i - 1].se - A[i - 1].fi);
}
vector<ll> minSufDiff(N + 7, 0LL);
ll curMin = 0, curSum = 0;
for(int i = N; i >= 1; --i) {
curSum += diff[i];
curMin = min(curMin, curSum);
minSufDiff[i] = curSum - curMin;
}
ll ans = 0;
for(int i = 1; i <= N; ++i) {
ans = max(ans, A[i].se + minSufDiff[i + 1]);
}
cout << ans;
}
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... | ||||
