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;
typedef long long ll;
const int M = 1e7+5;
ll delivery(int N, int K, int L, int p[]) {
vector<ll> l(N+1,0),r(N+1,0),cnt(N+1,0);
for(int i=0;i<N;i++){
// prefix
cnt[i%K] += p[i]*2;
l[i] = cnt[i%K];
}
cnt.assign(N+1,0);
for(int i=N-1;i>=0;i--){
// suffix
cnt[i%K] += 2*(L-p[i]);
r[i] = cnt[i%K];
}
ll ans = 1e18;
for(int i=0;i<=N;i++){
// calc best answer
ans = min(ans,(i ? l[i-1] : 0)+r[i]);
}
for(int i=0;i<=N-K;i++){
// best answer with a full circle turn (max 1)
ans = min(ans,(i ? l[i-1] : 0)+r[i+K]+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... |