# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
947608 | 4QT0R | 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;
#define ll long long
ll pref[10000002];
ll suf[10000002];
ll delivery(ll n, ll k, ll l, ll positions[]){
for (int i = 0; i<k; i++)pref[i]=positions[i];
for (int i = k; i<n; i++)pref[i]=positions[i]+pref[i-k];
for (int i = n-1; i>n-k-1; i--)suf[i]=l-positions[i];
for (int i = n-k-1; i>=0; i--)suf[i]=l-positions[i]+suf[i+k];
ll ans=suf[0];
for (int i = 0; i<n-1; i++)ans=min(ans,2*pref[i]+2*suf[i+1]);
for (int i = 0; i<n-1; i++)ans=min(ans,2*pref[i]+l+2*(i+k<n ? suf[i+k] : suf[n-1]));
return ans;
}