#include <bits/stdc++.h>
using namespace std;
long long delivery(int N, int K, int L, int positions[]) {
vector<int> left(N), right(N);
for (int i = 0; i < N; i++) {
left[i] = positions[i];
if (positions[i] < L / 2) {
left[i] += positions[i];
} else {
left[i] = L;
}
if (i + 1 > K) {
left[i] += left[i - K];
}
}
for (int i = N - 1; i >= 0; i--) {
right[i] = L - positions[i];
if (L <= positions[i] + L / 2) {
right[i] += (L - positions[i]);
} else {
right[i] = L;
}
if (N - i > K) {
right[i] += right[i + K];
}
}
long long ans = 1ll * min(left[N - 1], right[0]);
for (int i = 1; i < N - 1; i++) {
ans = min(ans, 1ll * left[i] + right[i + 1]);
}
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... |