#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
long long get(int x, int L){
return (L - x) % L;
}
long long delivery(int N, int K, int L, int pos[]) {
auto dist = [&](int x){ return (x + L) % L; };
sort(pos, pos + N, [&](int a, int b){
return dist(a) < dist(b);
});
vector<long long> lcw(N+1, 0);
for (int i = 1; i <= N; ++i) {
long long d = dist(pos[i-1]);
if (i <= K) {
lcw[i] = 2*d;
} else {
lcw[i] = lcw[i - K] + 2*d;
}
}
vector<long long> rccw(N+1, 0);
for (int i = 1; i <= N; ++i) {
long long d = get(pos[N - i], L);
if (i <= K) {
rccw[i] = 2*d;
} else {
rccw[i] = rccw[i - K] + 2*d;
}
}
long long ans = LLONG_MAX;
for (int s = 0; s <= N; ++s) {
ans = min(ans, lcw[s] + rccw[N - s]);
}
int M = min(K, N);
for (int t = 0; t + M <= N; ++t) {
ans = min(ans, lcw[t] + (long long)L + rccw[N - (t + M)]);
}
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... |