# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
322422 | tigicha | 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>
using namespace std;
long long ans, dp1[10000001], dp2[10000001];
long long delivery(long long n, long long k, long long l, long long a[]){
for(long long i=0; i<n; i++)
if(i>=k) dp1[i+1]=2*a[i]+a[i-k+1];
else dp1[i+1]=2*a[i];
for(long long i=n-1; i>=0; i--)
if(i<n-k) dp2[i+1]=2*(l-a[i])+dp2[i+k+1];
else dp2[i+1]=2*(l-a[i]);
ans=min(dp1[n], dp2[1]);
for(long long i=1; i<=n-k+1; i++)
ans=min(ans, dp1[i-1]+l+dp2[i+k]);
for(long long i=1; i<n; i++)
ans=min(ans, dp1[i]+dp2[i+1]);
return ans;
}