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;
long long delivery(int N, int K, int L, int positions[]){
long long ans = LONG_LONG_MAX;
long long w[N], c[N];
for(int j = 0;j < N;j++){
if(j < K) w[j] = min(positions[j], L - positions[j]) + positions[j];
else w[j] = min(positions[j], L - positions[j]) + w[j-K] + positions[j];
}
for(int j = N-1;j >= 0;j--){
if(j + K >= N) c[j] = min(positions[j], L - positions[j]) + L - positions[j];
else c[j] = min(positions[j], L - positions[j]) + c[j+K] + L - positions[j];
}
for(int i = -1;i < N;i++){
if(i == -1) ans = min(ans, c[0]);
else if (i == N - 1) ans = min(ans, w[N-1]);
else ans = min(ans, w[i] + c[i+1]);
}
return ans;
}
//int main(){
// int p[] = {1, 9, 11, 19};
// cout << delivery(4, 2, 20, p) << '\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... |