# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
416465 | kevinxiehk | 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"
#include "bits/stdc++.h"
#define int long long
#define iint int
using namespace std;
long long delivery(iint n, iint k, iint l, iint p[]) {
int le[n + 5], lcnt = 0;
int ri[n + 5], rcnt = 0;
int ii = 0;
while(ii < n && p[ii] <= l / 2) {
le[lcnt] = p[ii];
lcnt++;
ii++;
}
while(ii < n) {
ri[rcnt] = l - p[ii];
rcnt++;
ii++;
}
reverse(ri, ri + rcnt);
int ll[lcnt + 5], rr[rcnt + 5];
ll[0] = 0, rr[0] = 0;
for(int i = 1; i <= lcnt; i++) {
ll[i] = (i <= k ? le[i - 1] * 2 : ll[i - k] + le[i - 1] * 2);
}
for(int i = 1; i <= rcnt; i++) {
rr[i] = (i <= k ? ri[i - 1] * 2 : rr[i - k] + ri[i - 1] * 2);
}
int ans = ll[lcnt] + rr[rcnt];
for(int i = 0; i <= k; i++) {
int lef = i;
int rig = k - i;
ans = min(ans, l + ll[max(0LL, lcnt - lef)] + rr[max(0LL, rcnt - rig)]);
}
return ans;
}