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;
using ll = long long;
ll delivery(int n, int k, int L, int p[]) {
auto dist = [&](int i, int j) -> int {
return min(abs(i - j), L - abs(i - j));
};
sort(p, p + n);
vector<ll> pref(n), suff(n + 1);
int left = 0;
bool nw = true;
for (int i = 0; i < n; i++) {
pref[i] = i > 0 ? pref[i - 1] : 0;
if (left == 0) {
left = k;
nw = true;
}
pref[i] += dist(nw ? 0 : p[i - 1], p[i]) * 2;
left--;
nw = false;
}
left = 0;
for (int i = n - 1; i >= 0; i--) {
suff[i] = suff[i + 1];
if (left == 0) {
left = k;
nw = true;
}
suff[i] += dist(nw ? 0 : p[i + 1], p[i]) * 2;
left--;
nw = false;
}
ll ans = min(pref[n - 1], suff[0]);
for (int i = 1; i < n; i++) {
ans = min(ans, pref[i - 1] + suff[i]);
}
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... |