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 "boxes.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL INF=1e18;
LL dist(LL x,LL y,LL mod){
return min((y-x+mod)%mod,(x-y+mod)%mod);
}
LL cost(LL a,LL b,LL mod){
return dist(a,0,mod)+(b-a+mod)%mod+dist(b,0,mod);
}
LL delivery(int N, int K, int L, int p[]) {
LL ans=INF;
for(LL i=0;i<K;i++){
//i di kiri, K-i di kanan
LL ret=0;
if(i!=0)ret+=cost(p[0],p[i-1],L);
for(LL j=i;j<N;j+=K)ret+=cost(p[j],p[min(j+K-1,(LL)N-1)],L);
ans=min(ans,ret);
}
return ans;
}
/*
int main()
{
int n,k,l,i,a[101010];
cin>>n>>k>>l;
for(i=0;i<n;i++)
cin>>a[i];
cout<<delivery(n,k,l,a)<<"\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... |