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 <algorithm>
using namespace std;
#define long long long
const int N = 2e7 + 2;
long fsuff[N], fpref[N];
long delivery(int n, int k, int L, int p[]) {
int head = 0;
while (head < n && p[head] == 0) ++head;
long res = (long) (n - head + k - 1) / k * L;
for (int i = n - 1; i >= head; --i)
fsuff[i] = fsuff[i + k] + (L - p[i]) * 2;
int r = head;
while (r < n && fsuff[r] > fsuff[r + k] + L) r += k;
for (int i = head; i < n; ++i)
{
fpref[i] = (i < k ? 0 : fpref[i - k]) + p[i] * 2;
#define eval(x) (fsuff[x] + (long) (x - i - 1 + k - 1) / k * L)
while (r > i + 1 && eval(r - 1) < eval(r)) --r;
while (r < n && eval(r + 1) < eval(r)) ++r;
res = min(res, fpref[i] + eval(r));
#undef eval
}
return res;
}
# | 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... |