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>
#define ll long long
using namespace std;
ll delivery(int N, int K, int L, int positions[]){
vector<int> arr; arr.push_back(0);
for(int i = 0;i<N;++i) arr.push_back(positions[i]);
vector<ll> pref(N+2,0),suf(N+2,0);
for(int i = 1;i<=N;++i){
pref[i] = arr[i]*2LL + (i > K ? pref[i-K] : 0);
}
for(int i = N;i>=1;--i){
suf[i] = (L-arr[i])*2LL + (i > N-K+1 ? 0 : suf[i+K]);
}
ll ans = suf[1];
for(int i = 0;i<=N;++i){
ans = min(ans,pref[i]+suf[i+1]);
if(i+K <= N) ans = min(ans,pref[i]+L+suf[i+K+1]);
else ans = min(ans,pref[i]+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... |