# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
213303 | arman_ferdous | 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 <bits/stdc++.h>
using namespace std;
using ll = long long;
long long delivery(int n, int k, int l, int p[]) {
n = _n, k = _k, l = _l;
ll dp1[n + 1], dp2[n + 1];
dp1[0] = dp2[0] = 0;
for(int i = 1; i <= n; i++) {
dp1[i] = 2ll * p[i - 1] + (i - k >= 0 ? dp1[i - k] : 0);
dp2[i] = 2ll * (l - p[n - i]) + (i - k >= 0 ? dp2[i - k] : 0);
}
ll ans = 1e18;
for(int i = 0; i <= n; i++) {
ans = min(ans, dp1[i] + dp2[n - i]);
if(n - i - k >= 0)
ans = min(ans, dp1[i] + dp2[n - i - k] + l);
}
return ans;
}