#include <bits/stdc++.h>
#include "boxes.h"
using namespace std;
long long n, k, l, m, cnt, t, a, lft[10000], ans, x, y, v, ans1, rt[10000], curr;
long long delivery(int N, int K, int L, int p[]) {
n = N;
k = K;
l = L;
for (int i = 0; i < n; i++) {
if (p[i] <= l-p[i]) lft[a] = p[i], a++;
else rt[v] = l-p[i], v++;
}
t = a-k+1;
ans = 1e18;
for (int i = 0; i < k; i++) {
curr = ans;
ans = 0;
x = t+i;
y = t+i+k;
if (t < 0) t = 0;
for (int j = 0; j < x; j++) {
cnt++;
if (cnt%k == 0) ans += 2*p[j], cnt = 0;
}
if (cnt) ans += 2*p[x-1], cnt = 0;
for (int j = t+i+k; j < n; j++) {
cnt++;
if (cnt%k == 0) ans += (l-p[j-k+1])*2, cnt = 0;
}
if (cnt) ans += 2*(l - p[n-cnt%k]), cnt = 0;
ans = min(ans, curr);
}
ans += l;
for (int i = 0; i < a; i++) {
cnt++;
if (cnt%k == 0) ans1 += lft[i], cnt = 0;
}
if (cnt) ans1 += 2*lft[a-1], cnt = 0;
sort(rt,rt+v);
for (int i = 0; i < v; i++) {
cnt++;
if (cnt%k == 0) ans1 += rt[i], cnt = 0;
}
if (cnt) ans1 += 2*rt[v-1], cnt = 0;
return min(2*ans1,ans);
}
Compilation message
boxes.cpp: In function 'long long int delivery(int, int, int, int*)':
boxes.cpp:26:19: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
for (int j = t+i+k; j < n; j++) {
~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
376 KB |
Output is correct |
2 |
Correct |
9 ms |
376 KB |
Output is correct |
3 |
Correct |
9 ms |
376 KB |
Output is correct |
4 |
Correct |
9 ms |
504 KB |
Output is correct |
5 |
Incorrect |
9 ms |
404 KB |
Output isn't correct |
6 |
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 |
3 ms |
380 KB |
Output is correct |
4 |
Correct |
2 ms |
380 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 |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
8 ms |
376 KB |
Output is correct |
9 |
Correct |
9 ms |
376 KB |
Output is correct |
10 |
Correct |
9 ms |
376 KB |
Output is correct |
11 |
Correct |
9 ms |
504 KB |
Output is correct |
12 |
Incorrect |
9 ms |
404 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
8 ms |
376 KB |
Output is correct |
9 |
Correct |
9 ms |
376 KB |
Output is correct |
10 |
Correct |
9 ms |
376 KB |
Output is correct |
11 |
Correct |
9 ms |
504 KB |
Output is correct |
12 |
Incorrect |
9 ms |
404 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
8 ms |
376 KB |
Output is correct |
9 |
Correct |
9 ms |
376 KB |
Output is correct |
10 |
Correct |
9 ms |
376 KB |
Output is correct |
11 |
Correct |
9 ms |
504 KB |
Output is correct |
12 |
Incorrect |
9 ms |
404 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |