#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
long long delivery(int N, int K, int L, int pos[]) {
auto distCW = [&](int a, int b){ return (b - a + L) % L; };
auto distCCW = [&](int a, int b){ return (a - b + L) % L; };
sort(pos, pos + N, [&](int a, int b) {
return distCW(0, a) < distCW(0, b);
});
vector<vector<long long>> cost(N, vector<long long>(N, INF));
for (int i = 0; i < N; i++) {
long long farCW = 0, farCCW = 0;
for (int j = i; j < N && j - i + 1 <= K; j++) {
farCW = max(farCW, (long long)distCW(0, pos[j]));
cost[i][j] = min(cost[i][j], 2 * farCW);
farCCW = max(farCCW, (long long)distCCW(0, pos[j]));
cost[i][j] = min(cost[i][j], 2 * farCCW);
if (j - i + 1 == K) {
cost[i][j] = min(cost[i][j], (long long)L);
}
}
}
vector<long long> dp(N + 1, INF);
dp[0] = 0;
for (int i = 1; i <= N; i++) {
for (int j = max(0, i - K); j < i; j++) {
dp[i] = min(dp[i], dp[j] + cost[j][i - 1]);
}
}
return dp[N];
}
# | 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... |