# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
666285 | jamezzz | Boxes with souvenirs (IOI15_boxes) | C++17 | 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"
#define LINF 1023456789123456789
typedef long long ll;
#define maxn 10000005
ll pfx[maxn], sfx[maxn];
ll delivery(int N, int K, int L, int p[]){
sort(p, p + N);
for (int i = 0; i < N; ++i) {
sfx[i % K] += L - p[i];
}
ll ans = LINF;
for (int i = 0; i < N; ++i) {
pfx[i % K] += p[i];
sfx[i % K] -= L - p[i];
ans = min(ans, pfx[i % K] * 2 + sfx[(i + 1) % K] * 2);
}
return ans;
}