# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
390214 | mariowong | 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 <bits/stdc++.h>
using namespace std;
long long n,m,l,a[10000005],dp[10000005];
deque <int> dq;
int main(){
ios::sync_with_stdio(false);
cin >> n >> m >> l;
for (int i=1;i<=n;i++){
cin >> a[i];
}
for (int i=1;i<=n;i++){
while (!dq.empty() && dq.front()+m <= i) dq.pop_front();
if (!dq.empty())
dp[i]=min(dp[max(0LL,i-m)]+a[i]*2,dp[dq.front()]+2*l-2*a[dq.front()+1]);
else
dp[i]=dp[max(0LL,i-m)]+a[i]*2;
while (!dq.empty() && dp[dq.back()]-2*a[dq.back()+1] > dp[i]-2*a[i+1])
dq.pop_back();
dq.push_back(i);
}
cout << dp[n] << "\n";
return 0;
}