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 "boxes.h"
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define INF 99999999999999
#define all(x) x.begin(),x.end()
typedef long long ll;
long long delivery(int N, int K, int L, int p[]) {
ll n=N;
vector<ll>v;
    for(int i=0;i<n;i++)
        v.pb(i);
    ll ans=INF;
    do
    {
    ll curr=min(p[v[0]],L-p[v[0]]);
    ll count=K-1;
    for(int i=0;i<n-1;i++)
    {
        
        if(count==0)
        {
            curr+=min(p[v[i]],L-p[v[i]]);
            count=K;
        }
        count--;
        curr+=min(abs(p[v[i]]-p[v[i+1]]), min(p[v[i+1]],L-p[v[i+1]]) + min(p[v[i]],L-p[v[i]]));
        
    }
    curr+=min(p[v[n-1]] , L - p[v[n-1]]);
    ans=min(ans,curr);
    } while (next_permutation(all(v)));
    
    return ans;
}
| # | 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... |