# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1091548 | triplem5ds | 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>
long long cost1[10000007];
long long cost2[10000007];
using namespace std;
long long delivery(int N, int K, int L, int p[]) {
if(N == 1) return min(p[0], L - p[0]);
for(int i = 0; i < K; i++) {
long long cur1 = 0, cur2 = 0;
for(int j = i; j < N; j+=K) {
cur1 += min(p[j]*2,L);
cur2 += min((L-p[N-1-j])*2,L);
cost1[j] = cur1;
cost2[j] = cur2;
}
}
long long ans = min(cost1[N - 1], cost2[N - 1]);
for(int i = 0; i < N - 1; i++) {
ans = min(ans, cost1[i] + cost2[N-1-(i+1)]);
}
return ans;
}
int main() {
int p[3] = {1,2,5};
cout << delivery(3,2,8,p);
}