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;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
ll delivery(int N,int K,int L,int pos[]){
ll pre[N+5],suf[N+5],ans=1e18;
suf[N]=0;
for(int i=0;i<K;i++){
pre[i]=pos[i];
}
for(int i=K;i<N;i++){
pre[i]=pre[i-K]+pos[i];
}
for(int i=N-1;i>=N-K;i--){
suf[i]=L-pos[i];
}
for(int i=N-K-1;i>=0;i--){
suf[i]=suf[i+K]+(L-pos[i]);
}
ans=min(ans,suf[0]*2);
for(int i=0;i<N;i++){
ans=min(ans,pre[i]*2+suf[i+1]*2);
}
ans=min(ans,suf[K]*2+L);
for(int i=K;i<=N;i++){
ans=min(ans,pre[i-K]*2+suf[i+1]*2+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... |