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;
long long delivery(int N, int K, int L, int p[]) {
long long ans = 9e18, dp[N], dq[N];
for (int i = 0; i < N; ++i) {
dp[i] = 2 * p[i];
if (i >= K) {
dp[i] = 2 * p[i] + dp[i - K];
}
}
for (int i = N - 1; ~i; --i) {
dq[i] = 2 * (L - p[i]);
if (i + K < N) {
dq[i] = 2 * (L - p[i]) + dq[i + K];
}
}
ans = min(dp[N - 1], dq[0]);
for (int i = 0; i + 1 < N; ++i) {
ans = min(ans, dp[i] + dq[i + 1]);
}
for (int i = 0; i + K - 1 < N; ++i) {
ans = min(ans, dp[i] + dq[i + K - 1] + L);
}
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... |