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;
using ll = long long;
const int N = 1e7 + 5;
ll pref[N], suff[N];
int *p;
ll delivery(int n, int k, int m, int _p[]) { // n <= m, duoc dua toi da k
if (m == 1) return 0;
// if (n == 1) return min({m - 1, p[0] * 2, });
p = _p;
for (int i = 0; i < n; i++) {
pref[i] = (i - k >= 0 ? pref[i - k] : 0) + 2LL * p[i];
}
for (int i = n - 1; i >= 0; i--) {
suff[i] = (i + k < n ? suff[i + k] : 0) + 2LL * (m - p[i]);
}
ll ans = min(1LL * m * n, suff[0]);
for (int i = 0; i < n; i++) {
ans = min(ans, pref[i] + suff[i + 1]);
ll cur = 0;
if (i - 1 >= 0) cur += pref[i - 1];
if (i + k < n) cur += suff[i + k];
cur += m;
ans = min(ans, cur);
}
return ans;
}
# | 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... |