# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
320367 | nikatamliani | Boxes with souvenirs (IOI15_boxes) | C++14 | 0 ms | 0 KiB |
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;
int delivery(int N, int K, int L, int positions[]) {
long long p[N], s[N];
for(int i = 0; i < N; ++i) {
p[i] = 2 * positions[i];
if(i >= K) {
p[i] += p[i - K];
}
}
for(int i = N - 1; i >= 0; --i) {
s[i] = 2 * (L - positions[i]);
if(i + K < N) {
s[i] += s[i + K];
}
}
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';
// }