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>
long long dist(long long place, int L) {
return std::min(place, (long long) L - place);
}
struct Range {
int l, r;
long long get(int L, int pos[]) {
return
llabs((long long) pos[l] - (long long) pos[r]) +
dist(pos[l], L) + dist(pos[r], L);
}
};
long long delivery(int n, int k, int L, int pos[]) {
std::sort(pos, pos + n);
std::vector <Range> range((n + k - 1) / k);
long long ans = 0;
for (int i = 0; i < (n + k - 1) / k; i++) {
int l = i * k;
int r = std::min(l + k - 1, n - 1);
range[i] = { l, r };
ans += range[i].get(L, pos);
}
for (int i = 0; i <= k; i++) {
long long now = 0;
for (Range& ran : range) {
ran.l++;
ran.r++;
ran.l %= n;
ran.r %= n;
now += ran.get(L, pos);
}
ans = std::min(ans, now);
}
return ans;
}
//int main() {
//int a[3] = { 1, 2, 5 };
//std::cout << delivery(3, 2, 8, a) << std::endl;
//}
# | 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... |