This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* author: milos
* created: 10.03.2021 17:16:12
**/
#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
long long delivery(int n, int k, int l, int* a) {
sort(a, a + n);
vector<long long> pref(n, 0LL);
for (int i = 0; i < n; i++) {
if (i > 0) {
pref[i] = pref[i - 1];
}
if (i % k != 0) {
pref[i] -= a[i - 1] * 2;
}
pref[i] += a[i] * 2;
}
vector<long long> suff(n, 0LL);
for (int i = n - 1; i >= 0; i--) {
if (i < n - 1) {
suff[i] = suff[i + 1];
}
if ((n - i - 1) % k != 0) {
suff[i] -= (l - a[i + 1]) * 2;
}
suff[i] += (l - a[i]) * 2;
}
/*for (int i = 0; i < n; i++) {
cout << pref[i] << " ";
}
cout << '\n';
for (int i = 0; i < n; i++) {
cout << suff[i] << " ";
}
cout << '\n';*/
long long ans = suff[0];
for (int i = 0; i < n; i++) {
ans = min(ans, pref[i] + (i < n - 1 ? suff[i + 1] : 0LL));
}
if (k == n) {
ans = min(ans, (long long) l);
} else {
//ans = min(ans, (long long) l + suff[k]);
}
for (int i = 0; i < n; i++) {
ans = min(ans, pref[i] + (i < n - k - 1 ? suff[i + k + 1] : 0LL) + 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... |