# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
705332 | bin9638 | 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
#define fs first
#define sc second
#define N 10000010
#define pb push_back
ll sum_left[N],sum_right[N];
ll delivery(int n,int k,int l,ll a[])
{
for(int i=1;i<=n;i++)
if(i<=k)
sum_left[i]=a[i-1]+min(a[i-1],l-a[i-1]);
else sum_left[i]=sum_left[i-k]+1ll*a[i-1]+min(a[i-1],l-a[i-1]);
for(int i=n;i>=1;i--)
if(i+k-1>=n)
sum_right[i]=l-a[i-1]+min(a[i-1],l-a[i-1]);
else sum_right[i]=sum_right[i+k]+1ll*l-a[i-1]+min(a[i-1],l-a[i-1]);
ll res=min(sum_left[n],sum_right[1]);
for(int i=1;i<n;i++)
res=min(res,sum_left[i]+sum_right[i+1]);
return res;
}
#ifdef SKY
int main()
{
freopen("A.inp","r",stdin);
freopen("A.out","w",stdout);
// ios::sync_with_stdio(0);
// cin.tie(NULL);
// cout.tie(NULL);
int n,k,l;
cin>>n>>k>>l;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
cout<<delivery(n,k,l,a);
return 0;
}
#endif // SKY