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 "boxes.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back
int n, k, l;
vector<int> v;
int st1() {
int ans = 0;
for (int i = 1; i <= n; i++) ans += min(l, min(v[i], l - v[i]) * 2);
return ans;
}
int st2() {
int ans = min(l, min(v[n], l - v[1]) * 2);
// ???
cerr << ans << endl;
return ans;
}
int clear(int lb, int rb) {
return min(l, min(v[rb], l - v[lb]) * 2);
}
int st5() {
// idk anymore
// what was I doing... it is obviously wrong...
int asc[n + 2], desc[n + 2];
multiset<int> ms;
// ascending: min(l, a[rb] * 2) -> only care about rb
ms.clear(); ms.insert(0);
asc[0] = 0; asc[n + 1] = 1e18;
for (int i = 1; i <= n; i++) {
asc[i] = *ms.begin() + min(l, v[i] * 2);
ms.insert(asc[i]);
if (i >= k) ms.erase(ms.find(asc[i - k]));
}
// descending: min(l, (l - a[lb]) * 2) -> only care about lb
ms.clear(); ms.insert(0);
desc[n + 1] = 0; desc[0] = 1e18;
for (int i = n; i >= 1; i--) {
desc[i] = *ms.begin() + min(l, (l - v[i]) * 2);
ms.insert(desc[i]);
if (i + k <= n + 1) ms.erase(ms.find(desc[i + k]));
}
int ans = 1e18;
for (int i = 0; i <= n; i++) {
ans = min(ans, asc[i] + desc[i + 1]);
}
return ans;
}
int st6() {
int asc[n + 2], desc[n + 2];
// ascending: min(l, a[rb] * 2) -> only care about rb
asc[0] = 0; asc[n + 1] = 1e18;
for (int i = 1; i <= k; i++) {
asc[i] = min(l, v[i] * 2);
}
for (int i = k + 1; i <= n; i++) {
asc[i] = asc[i - k] + min(l, v[i] * 2);
}
// descending: min(l, (l - a[lb]) * 2) -> only care about lb
desc[n + 1] = 0; desc[0] = 1e18;
for (int i = n; i > n - k; i--) {
desc[i] = min(l, (l - v[i]) * 2);
}
for (int i = n - k; i >= 1; i--) {
desc[i] = desc[i + k] + min(l, (l - v[i]) * 2);
}
int ans = 1e18;
for (int i = 0; i <= n; i++) {
ans = min(ans, asc[i] + desc[i + 1]);
}
return ans;
}
long long delivery(int32_t N, int32_t K, int32_t L, int32_t p[]) {
l = L; v.clear(); v.pb(-1);
for (int i = 0; i < N; i++) if (p[i] > 0) v.pb(p[i]);
sort(v.begin(), v.end());
n = (int)(v.size()) - 1; k = min((int)(K), n);
if (n == 0) return 0;
return st6();
throw runtime_error("not yet");
}
#undef int
/*
subtasks 1-3 trivial
subtask 4 should be O(n^2) left-right dp
*/
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |