#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int N, K;
long long T, X[100000], m;
bool check() {
long long arr[N];
for (int i = 0; i < N; ++i) arr[i] = 2 * m * T * i - X[i];
int l = K - 1, r = K - 1, ml = min_element(arr, arr + K) - arr, mr = max_element(arr + K - 1, arr + N) - arr;
long long rl = arr[K - 1], rr = arr[K - 1];
while (l > ml || r < mr) {
bool ch = false;
while (l > ml && arr[l - 1] <= rr) rl = min(rl, arr[--l]), ch = true;
while (r < mr && arr[r + 1] >= rl) rr = max(rr, arr[++r]), ch = true;
if (!ch) return false;
}
l = 0, r = N - 1, rl = arr[0], rr = arr[N - 1];
if (rl > rr) return false;
while (l < ml || r > mr) {
bool ch = false;
while (l < ml && arr[l + 1] <= rr) rl = min(rl, arr[++l]), ch = true;
while (r > mr && arr[r - 1] >= rl) rr = max(rr, arr[--r]), ch = true;
if (!ch) return false;
}
return true;
}
int main() {
scanf("%d %d %lld", &N, &K, &T);
for (int i = 0; i < N; ++i) scanf("%lld", &X[i]);
long long l = 0, u = 10000000000 / T;
while (l != u) {
m = (l + u) / 2;
if (!check()) l = m + 1;
else u = m;
}
printf("%lld", l);
return 0;
}
Compilation message
sparklers.cpp: In function 'int main()':
sparklers.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | scanf("%d %d %lld", &N, &K, &T);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
sparklers.cpp:30:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | for (int i = 0; i < N; ++i) scanf("%lld", &X[i]);
| ~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
288 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
1 ms |
204 KB |
Output is correct |
37 |
Correct |
1 ms |
204 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
0 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
288 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
1 ms |
204 KB |
Output is correct |
33 |
Correct |
1 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
1 ms |
204 KB |
Output is correct |
36 |
Correct |
1 ms |
204 KB |
Output is correct |
37 |
Correct |
1 ms |
204 KB |
Output is correct |
38 |
Correct |
1 ms |
204 KB |
Output is correct |
39 |
Correct |
1 ms |
204 KB |
Output is correct |
40 |
Correct |
1 ms |
204 KB |
Output is correct |
41 |
Correct |
20 ms |
1892 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
6 ms |
716 KB |
Output is correct |
44 |
Correct |
34 ms |
2764 KB |
Output is correct |
45 |
Correct |
35 ms |
2776 KB |
Output is correct |
46 |
Correct |
30 ms |
2668 KB |
Output is correct |
47 |
Correct |
30 ms |
2780 KB |
Output is correct |
48 |
Correct |
39 ms |
2764 KB |
Output is correct |
49 |
Correct |
29 ms |
2692 KB |
Output is correct |
50 |
Correct |
36 ms |
2780 KB |
Output is correct |
51 |
Correct |
31 ms |
2756 KB |
Output is correct |
52 |
Correct |
31 ms |
2800 KB |
Output is correct |
53 |
Correct |
31 ms |
2764 KB |
Output is correct |
54 |
Correct |
36 ms |
2796 KB |
Output is correct |
55 |
Correct |
30 ms |
2764 KB |
Output is correct |
56 |
Correct |
36 ms |
2708 KB |
Output is correct |
57 |
Correct |
29 ms |
2764 KB |
Output is correct |
58 |
Correct |
40 ms |
2776 KB |
Output is correct |
59 |
Correct |
27 ms |
1960 KB |
Output is correct |
60 |
Correct |
35 ms |
2884 KB |
Output is correct |
61 |
Correct |
33 ms |
2616 KB |
Output is correct |
62 |
Correct |
30 ms |
2756 KB |
Output is correct |
63 |
Correct |
31 ms |
2800 KB |
Output is correct |
64 |
Correct |
34 ms |
2656 KB |
Output is correct |
65 |
Correct |
31 ms |
2748 KB |
Output is correct |
66 |
Correct |
31 ms |
2752 KB |
Output is correct |
67 |
Correct |
29 ms |
2764 KB |
Output is correct |
68 |
Correct |
30 ms |
2712 KB |
Output is correct |
69 |
Correct |
29 ms |
2704 KB |
Output is correct |