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;
const LL INF = 1e18;
LL solve(int n, int k, int l, vector<int> p) {
sort(p.begin(), p.end());
vector<vector<LL>> dp(n+1, vector<LL>(n+1, INF));
dp[0][0] = 0;
for (int a = 0; a <= n; ++a) {
for (int b = 0; a + b <= n; ++b) {
for (int s = 1; s <= k && s <= a; ++s) {
dp[a][b] = min(dp[a][b], dp[a - s][b] + p[a - 1]);
}
for (int s = 1; s <= k && s <= b; ++s) {
dp[a][b] = min(dp[a][b], dp[a][b - s] + l - p[n - b]);
}
}
}
LL ans = INF;
for (int i = 0; i <= n; ++i) {
ans = min(ans, dp[i][n - i]);
}
return 2 * ans;
}
LL delivery(int n, int k, int l, int p[]) {
vector<int> v; // those you don't take greedily
for (int i = 0; i < n; ++i) {
v.push_back(p[i]);
}
return solve(n, k, l, v);
}
# | 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... |