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 <bits/stdc++.h>
#include "boxes.h"
using namespace std;
long long delivery(int N, int K, int L, int positions[]) {
long long p[N], s[N];
for(int i = 0; i < N; ++i) {
p[i] = positions[i];
if(i >= K) {
p[i] += p[i - K];
}
p[i] *= 2;
}
for(int i = N - 1; i >= 0; --i) {
s[i] = L - positions[i];
if(i + K < N) {
s[i] += s[i + K];
}
s[i] *= 2;
}
long long answer = p[N - 1];
for(int i = 0; i < N - 1; ++i) {
answer = min(answer, p[i] + s[i + 1]);
}
for(int start = 0; start + K - 1 < N; ++start) {
int end = start + K - 1;
long long left = (start > 0 ? p[start - 1] : 0);
long long right = (end < N - 1 ? s[end + 1] : 0);
long long middle = L;
answer = min(answer, left + middle + right);
}
return answer;
}
// int main() {
// int pos[] = {1, 2, 5};
// cout << delivery(3, 2, 8, pos) << '\n';
// }
# | 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... |