#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[]) {
return cost(p[0],p[N-1],L);
LL sisa=N%K,ans=INF;
for(LL i=0;i<=sisa;i++){
//i di kiri, sisa-i di kanan
LL ret=0;
if(i!=0)ret+=cost(p[0],p[i-1],L);
for(LL j=1;j<=N/K;j++)ret+=cost(p[i+(j-1)*K],p[i+j*K-1],L);
if(sisa!=i)ret+=cost(p[N-sisa+i],p[N-1],L);
ans=min(ans,ret);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |