# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
123884 | khulegub | 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 "boxes.h"
#include <algorithm>
#include <cstring>
#define pb push_back
using namespace std;
typedef long long i64;
i64 lsum[10000010], rsum[10000010];
i64 zeze[10000010];
int n;
int l;
int k;
i64 delivery(int N, int K, int L, int p[]) {
n = N;
l = L;
k = K;
for (int i = 0; i < n; i++){
zeze[i % k] += 2 * p[i];
lsum[i] = zeze[i % k];
}
memset(zeze, 0, sizeof zeze);
for (int i = n - 1; i >= 0; i--){
zeze[i % k] += 2 * (l - p[i]);
rsum[i] = zeze[i % k];
}
i64 ans = 1e9;
for (int i = 0; i <= n; i++){
if (i == 0) ans = min(ans, rsum[i]);
else ans = min(ans, lsum[i - 1] + rsum[i]);
}
for (int i = 0; i <= n - k; i++){
if (i == 0) ans = min(ans, rsum[i + k] + l);
else ans = min(ans, lsum[i - 1] + rsum[i + k] + l)
}
return ans;
}