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 <bits/stdc++.h>
#include "boxes.h"
using namespace std;
const int nax = 1e3 + 3;
const long long INF = 1e18;
long long dp[nax];
int n, k, L;
int a[nax];
int c[nax];
long long delivery(int N, int K, int l, int p[]) {
n = N, k = K, L = l;
for(int i=1; i<=n; ++i) {
a[i] = p[i-1];
c[i] = min(a[i], L-a[i]);
}
a[n+1] = 2e9 + 10;
for(int i=1; i<=n+1; ++i) {
dp[i] = INF;
}
dp[1] = c[1];
//dp is increasing
//dp[i] = # of seconds to fill [1...i] with k-1 gifts remaining
for(int i=2; i<=n; ++i) {
for(int j=i-1; j>0 && i-j<=k; --j) {
dp[i] = min(dp[i],
dp[j] + min(a[i-1]-a[j], a[j+1]-a[j]));
}
dp[i] += c[i-1] + c[i];
}
long long ans = INF;
for(int i=1; i<=n; ++i) {
if(i+k-1>=n) {
ans = min(ans, dp[i] + L-a[i]);
if(i==n) ans = min(ans, dp[i] + a[i]);
}
}
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... |