#include <bits/stdc++.h>
using namespace std;
long long delivery(int N, int K, int L, int positions[]) {
	vector<int> position;
	int n = N;
	for (int i = 0; i < N; i++) {
		if (positions[i] != 0) {
			position.push_back(i);
		} else {
			n--;
		}
	}
	long long rot1[n+1] = {};
	long long rot2[n+1] = {};
	for (int i = 0; i < min(K,n); i++) {
		//wack st5 edge case 
		rot1[i+1] = 2ll*(long long)position[i];
		rot2[i+1] = 2ll*(long long)(L-position[n-i-1]);
	}
	for (int i = K; i < n; i++) {
		int x = (i-1)/K;
		x *= K;
		rot1[i+1] = rot1[x+1]+2ll*(long long)position[i];
		rot2[i+1] = rot2[x+1]+2ll*(long long)(L-position[n-i-1]);
	}
	long long ans = 1e18;
	for (int i = 0; i <= n; i++) {
		ans = min(ans,rot1[i]+rot2[n-i]);
	}
	for (int i = 0; i <= n-K; i++) {
		ans = min(ans,rot1[i]+rot2[n-i-K]+(long long)L);
	}
	if (n <= K) {
		//edge case of n <= K allows for 1 trip around if that's optimal
		ans = min(ans,(long long)L);
	}
	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... |