This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifndef LOCAL
#include "boxes.h"
#endif // LOCAL
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ar array
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
const int maxn = 1e7 + 5;
ll f[maxn][2];
long long delivery(int N, int K, int L, int p[])
{
for(int i = 0; i < N; ++i){
if(i < K) f[i][0] = 2 * p[i];
else f[i][0] = f[i - K][0] + 2 * p[i];
}
for(int i = N - 1; i >= 0; --i){
if(i + K >= N) f[i][1] = 2 * (L - p[i]);
else f[i][1] = f[i + K][1] + 2 * (L - p[i]);
}
ll res = min(f[N - 1][0], f[0][1]);
for(int i = -1; i < N - 1; ++i){
res = min(res, (i == -1 ? 0 : f[i][0]) + L + f[min(N, i + K + 1)][1]);
}
for(int i = N; i >= 0; --i){
res = min(res, f[i][1] + L + (i - K - 1 >= 0 ? f[i - K - 1][0] : 0));
}
for(int i = 0; i < N - 1; ++i){
res = min(res, f[i][0] + f[i + 1][1]);
}
return res;
}
#ifdef LOCAL
signed main(void)
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("A.INP", "r", stdin);
freopen("A.OUT", "w", stdout);
#endif // LOCAL
int _N, _K, _L;
cin >> _N >> _K >> _L;
int p[_N];
for(int i = 0; i < _N; ++i)
cin >> p[i];
cout << delivery(_N, _K, _L, p);
}
#endif // LOCAL
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |