#include<bits/stdc++.h>
#define ll long long
//#include "boxes.h"
using namespace std;
const int MAXN = 1e7+5;
ll L[MAXN], R[MAXN],dis[MAXN];
void F(int P[],int n,int k,ll X[]) {
for (int i = 0; i < n; i++) {
if (i % k == k - 1) {
X[i] = 2*P[i] + ( i >= k ? X[i-k] : 0);
}
else X[i] = 2*P[i] + ( i >= k ? X[i - (i + 1)%k] : 0);
}
}
ll delivery(int n, int k, int le, int P[]) {
sort (P,P+n);
reverse(P,P+n);
for (; n > 0 && P[n-1] == 0; n--);
// if (n == 0) return 0;
reverse(P,P+n);
// ll sum_L = 0;
F(P,n,k,L);
for (int i = 0; i < n; i++) P[i] = ( (le - P[i])%le );
reverse(P,P+n);
F(P,n,k,R);
reverse(P,P+n);
for (int i = 0; i < n; i++) P[i] = ( (le - P[i])%le );
// cout << L[0] << ' ';
ll ans = min(L[n-1],R[n-1]);
// for (int i = 0; i < n; i++) {
// ans = min(ans,L[i] + (le - P[i]) - P[i] + (i + 2 <= n? R[n - i - 2] : 0 ));
// ans = min(ans,R[(n - i - 1)] + P[i] - ( le - P[i] ) + (i ? L[i-1] : 0));
// }
// ans = min(ans,L[n-1] + (le - P[n-1]) - P[n-1]);
// ans = min(ans,R[n-1] + P[0] - (le - P[0]));
for (int i = 0; i < n; i++) {
ans = min(ans,L[i] + ( i != n-1 ? R[n - i - 2] : 0) );
}
return ans;
} /*
main() {
int n,k,l;
cin >> n >> k >> l;
int p[n];
for (int i = 0; i < n ; i++)
cin >> p[i];
cout << delivery(n,k,l,p) ;
// cout <<' '<< R[0] << ' '<<R[1] <<' '<<R[2];
// 3 2 8 1 2 5
} */
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Incorrect |
4 ms |
384 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |