#include<bits/stdc++.h>
#include "boxes.h"
#include<ext/pb_ds/assoc_container.hpp>
/**zagaro & lauren <3**/
#define mod 1000000007 //1e9 + 7
#define pi acos(-1)
#define wl while
#define str string
#define ENDL "\n"
#define sal ' '
#define tp_set ll
#define prc(n) cout.precision(n);cout<<fixed;
#define ord_set tree<tp_set, null_type, less<tp_set>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef bool bl;
typedef char car;
using namespace std;
using namespace __gnu_pbds;
ll delivery(int N, int K, int L, int p[]) {
    ll r=LONG_LONG_MAX, x, a, b;
    vector<ll> vec(N, LONG_LONG_MAX);
    vector<ll> vic(N, LONG_LONG_MAX);
    for(int i=0;i<min(N, K);i++){
        vec[i] = p[i]*2;
    }
    for(int i=0;i<min(N, K);i++){
        vic[N-i-1] = (L-p[N-i-1])*2;
    }
    x=1;
    for(int i=K;i<N;i++){
        if(p[i] <= L/2)a=2*p[i];
        else if(p[x] >= L/2)a=2*(L-p[x]);
        else a=L;
        vec[i] = vec[i-K] + a;
        x++;
    }
    x=N-2;
    for(int i=K;i<N;i++){
        if(p[N-i-1] >= L/2)a=2*(L-p[N-i-1]);
        else if(p[x] <= L/2)a=2*p[x];
        else a=L;
        vic[N-i-1] = vic[N-i+K-1] + a;
        x--;
    }
    if(N == K)r = min(r, ll(L));
    for(int i=1;i<N;i++)r = min(r, vec[i-1]+vic[i]);
    r = min(r, min(vec[N-1], vic[0]));
    return r;
}
| # | 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... |