# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
529957 | antonioqbab | 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 <iostream>
#include <vector>
#include <algorithm>
//#include <delivery.h>
using namespace std;
using ll = long long;
int delivery(int n, int k, int l, int a[]){
ll ans = INT_MAX;
vector<ll> dpl(n+2), dpr(n+2);
for(int i=1;i<=n;++i)
dpl[i]= dpl[max(i-k,0)] + 2*a[i-1];
for(int i=n;i;--i)
dpr[i]= dpr[min(i+k,n+1)] + 2*(l-a[i-1]);
for(int i=1;i<=n;++i)
ans=min(ans, dpl[i]+dpr[i+1]-l);
return ans;
}
int main(){
int n,k,l;
cin >> n >> k >> l;
int *v=new int[n];
for(int i=0;i<n;++i)
cin >> v[i];
cout << delivery(n,k,l,v);
}