#include <bits/stdc++.h>
#include "boxes.h"
using namespace std;
#define ll long long
#define vb vector<bool>
#define pb push_back
#define ff(aa, bb, cc) for(int aa = bb; aa < cc; aa++)
#define vl vector<ll>
#define pll pair<ll, ll>
#define fi first
#define se second
#define ed "\n"
#define all(aaa) aaa.begin(), aaa.end()
#define rall(aaa) aaa.rbegin(), aaa.rend()
ll MOD = 1e9+7;
long long delivery(int n, int k, int l, int p[]){
vl arr;
ff(i, 0, n){
if(p[i] == 0){
continue;
}
arr.pb(p[i]);
}
n = arr.size();
if(n == 0){
return 0;
}
vl left(n), right(n);
ff(i, 0, n){
left[i] = arr[i]*2;
if(i >= k){
left[i] += left[i-k];
}
}
for(ll i = n-1; i >= 0; i--){
right[i] = (l-arr[i])*2;
if((n-1-i) >= k){
right[i] += right[i+k];
}
}
/*cout << "LEFT " << ed;
ff(i, 0, n){
cout << left[i] << " ";
}
cout << ed << "RIGHT" << ed;
ff(i, 0, n){
cout << right[i] << " ";
}
cout << ed << ed;*/
ll minn = LLONG_MAX;
for(ll i = 0; i+k+1 < n; i++){
//cout << i << " " << i+k << " ";
minn = min(minn, l+left[i]+right[i+k+1]);
}
//cout << ed;
for(ll i = 0; i+1 < n; i++){
//cout << i << " " << i+1 << " ";
minn = min(minn, left[i]+right[i+1]);
}
minn = min({minn, left[n-1], right[0]});
if(n <= k){
minn = min(minn, (ll)l);
}
//cout << ed << ed;
return minn;
}
/*
int main() {
int N, K, L;
cin >> N >> K >> L;
int p[N];
ff(i, 0, N){
cin >> p[i];
}
long long ans = delivery(N, K, L, p);
cout << ans << ed;
return 0;
}
*/
# | 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... |