# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
729045 | kirakaminski968 | 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 <bits/stdc++.h>
using namespace std;
long long delivery(int N, int K, int L, int *positions[]){
long long ans = 0;
vector<long long> p; p.push_back(0);
for(auto c : positions) p.push_back(c);
long long pref[N + 2], suf[N + 2];
pref[0] = suf[N+1] = 0;
for(int i = 1;i <= N;++i)
{
pref[i] = (i<=K) ? a[i] * 2LL : p[i] * 2LL + pref[i - K];
}
for(int i = N;i>=1;--i)
{
suf[i] =(i+K-1>N) ? (L-p[i]) * 2LL : (L-a[i]) * 2LL + suf[i+K];
}
long long ans = suf[1];
for(int i = 0; i <= N; i++)
{
ans = min(ans,pref[i] + suf[i + 1]);
if(i+K <= N) ans = min(ans,pref[i]+L+suf[i + K + 1]);
else ans = min(ans, pref[i] + L);
}
return ans;
}