#include <bits/stdc++.h>
#include "boxes.h"
using namespace std;
#define mod 1000000007
#define maxn 200005
#define f first
#define s second
#define ll long long
#define pb(x) push_back(x)
#define mp make_pair
#define all(x) x.begin(), x.end()
#define len(v) max(0, (int)v.size())
long long delivery(int N, int k, int L, int p[]){
vector<int> l, r;
long long ans1=0, ans2=0;
for(int i=0; i<N; i++){
if(p[i]<(L+1)/2){
l.pb(p[i]);
}else{
r.pb(L-p[i]);
}
}
int i=0, j=0, n=len(l), m=len(r);
while(i<n){
int d=min(k, n-i);
ans1+=l[i+d-1]*2;
if(d!=k){
ans2=ans1-l[i+d-1]*2+L;
m=m-k+d;
}
i+=d;
}
reverse(r.begin(), r.end());
while(j<m){
int d=min(k, m-j);
ans2+=r[j+d-1]*2;
j+=d;
}
j=0; m=len(r);
while(j<m){
int d=min(k, m-j);
ans1+=r[j+d-1]*2;
j+=d;
}
return min(ans1, ans2);
}
| # | 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... |