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>
using namespace std;
int delivery(int n, int k, int l, int a[]){
int dp1[n + 1], dp2[n + 1], pos[n + 1]; dp1[0] = 0; dp2[0] = 0;
for(int i = 0; i < n; i++) pos[i + 1] = a[i];
sort(a + 1, a + n + 1);
for(int i = 1; i <= n ; i++){
dp1[i] = dp1[max(0, i - k)] + 2 * pos[i];
}
for(int i = 1; i <= n ; i++){
dp2[i] = 2 * (l - pos[i]) + dp2[min(n + 1, i + k)];
}
int ans = 1e9;
for (int i = 1;i < n + 1; i++) ans = min(ans, dp1[i - 1] + dp2[i]);
for (int i = k;i <= n; i++) ans = min(ans, dp1[i - k] + dp2[i + 1] + 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... |