This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// pragmas
#ifndef DEBUG
#endif
#include <bits/stdc++.h>
#include "boxes.h"
// #define int long long
using ll = long long;
using namespace std;
long long delivery(int N, int K, int L, int p[]) {
vector<int> cost_pref(N, 0);
for (int i=0; i<N; i++) {
if (i>=K) cost_pref[i] = cost_pref[i-K];
cost_pref[i] += 2*p[i];
}
vector<int> cost_suff(N, 0);
for (int i=N-1; i>=0; i--) {
if (i+K < N) cost_suff[i] = cost_suff[i+K];
cost_suff[i] += 2*(L-p[i]);
}
int res = min(cost_pref[N-1], cost_suff[0]);
for (int i=0; i<N; i++) {
res = min(res, cost_pref[i]+L+cost_suff[min(N-1, i+K+1)]);
res = min(res, cost_pref[i]+cost_suff[min(N-1, i+1)]);
}
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... |