#include "boxes.h"
#include <stdio.h>
#include <algorithm>
using namespace std;
const int MAX_N = 2e7;
const long long INF = 1e18;
int n, k, l;
int p[MAX_N + 1];
long long dp1[MAX_N + 1];
long long dp2[MAX_N + 1];
long long delivery(int N, int K, int L, int P[]) {
n = N;
k = K;
l = L;
for (int i = 1; i <= n; i++)
p[i] = P[i - 1];
sort(p + 1, p + 1 + n);
int pos = 0;
while (pos + 1 <= n && p[pos + 1] <= l / 2)
pos++;
for (int i = 1; i <= n; i++) {
if (i <= k)
dp1[i] = 2 * p[i];
else
dp1[i] = dp1[i - k] + 2 * p[i];
}
for (int i = n; i >= 1; i--) {
if (i >= n - k + 1)
dp2[i] = 2 * (l - p[i]);
else
dp2[i] = dp2[i + k] + 2 * p[i];
}
long long best = dp1[pos] + dp2[pos + 1];
for (int i = 1; i <= n - k + 1; i++) {
long long c1 = dp1[i - 1];
long long c2 = dp2[i + k];
best = min(best, c1 + c2 + l);
}
return best;
}
# | 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... |