# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
637233 | nehasane | 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"
using ll = long long;
long long delivery(int N, int K, int L, int p[]) {
ll ans = 0;
sort(positions, positions + N);
int x = K-1;
int st = positions[0], ed = positions[0];
for (int i = 1; i < N; i++) {
if (x > 0) {
ll new_grp = 0, old_grp = 0;
new_grp = min({L, (L - st) * 2, ed * 2}) + min({L, positions[i] * 2, (L - positions[i]) * 2});
old_grp = min({L, positions[i] * 2, (L - st) * 2});
if (new_grp <= old_grp) {
old_grp = min({L, (L - st) * 2, ed * 2});
ans += old_grp;
x = K - 1;
st = ed = positions[i];
} else {
x--;
ed = positions[i];
}
} else {
ll old_grp = min({L, (L - st) * 2, ed * 2});
ans += old_grp;
st = ed = positions[i];
x = K-1;
}
}
ans += min({L, (L - st) * 2, ed * 2});
return ans;
}