#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
const int OO = 1e9 + 10;
int n, t, k, A[N];
ll B[N];
bool out(int l, int r, int lo, int hi) { // lo <= l | r <= hi
int l_ = l, r_ = r;
for(; lo >= 0 && B[lo] >= B[r]; --lo) {
if(B[lo] > B[l_]) {
l_ = lo;
}
}
for(; hi < n && B[hi] <= B[l]; ++hi) {
if(B[hi] < B[r_]) {
r_ = hi;
}
}
if(lo < 0 && hi >= n) { return 1; }
if(l == l_ && r == r_) { return 0; }
return out(l_, r_, lo, hi);
}
bool in(int l, int r, int lo, int hi) { // lo <= l | r <= hi
int l_ = l, r_ = r;
for(; lo < k && B[lo] >= B[r]; ++lo) {
if(B[lo] > B[l_]) {
l_ = lo;
}
}
for(; hi > k - 2 && B[hi] <= B[l]; --hi) {
if(B[hi] < B[r_]) {
r_ = hi;
}
}
if(lo >= k && hi <= k - 2) { return 1; }
if(l == l_ && r == r_) { return 0; }
return in(l_, r_, lo, hi);
}
bool loop(int mi) {
for(int i = 0; i < n; ++i) {
B[i] = (ll) A[i] - (ll) 2 * mi * t * i;
}
return out(k - 1, k - 1, k - 2, k) & in(0, n - 1, 1, n - 2);
}
int main() {
scanf("%d%d%d", &n, &k, &t);
for(int i = 0; i < n; ++i) { scanf("%d", A + i); }
int lo = -1, hi = OO / t + 100;
for(int mi = (lo + hi) / 2; hi - lo > 1; mi = (lo + hi) / 2) {
bool res = loop(mi);
// printf("[%d %d %d] = %d\n", lo, mi, hi, res);
if(res) { hi = mi; }
else { lo = mi; }
}
printf("%d\n", hi);
return 0;
}
Compilation message
sparklers.cpp: In function 'int main()':
sparklers.cpp:65:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | scanf("%d%d%d", &n, &k, &t);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
sparklers.cpp:66:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | for(int i = 0; i < n; ++i) { scanf("%d", A + i); }
| ~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
428 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
428 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
344 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
428 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
344 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
344 KB |
Output is correct |
41 |
Correct |
15 ms |
1628 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
5 ms |
604 KB |
Output is correct |
44 |
Correct |
22 ms |
2396 KB |
Output is correct |
45 |
Correct |
24 ms |
2372 KB |
Output is correct |
46 |
Correct |
23 ms |
2392 KB |
Output is correct |
47 |
Correct |
25 ms |
2464 KB |
Output is correct |
48 |
Correct |
23 ms |
2396 KB |
Output is correct |
49 |
Correct |
23 ms |
2560 KB |
Output is correct |
50 |
Correct |
24 ms |
2396 KB |
Output is correct |
51 |
Correct |
24 ms |
2396 KB |
Output is correct |
52 |
Correct |
23 ms |
2396 KB |
Output is correct |
53 |
Correct |
24 ms |
2380 KB |
Output is correct |
54 |
Correct |
27 ms |
2384 KB |
Output is correct |
55 |
Correct |
24 ms |
2396 KB |
Output is correct |
56 |
Correct |
22 ms |
2528 KB |
Output is correct |
57 |
Correct |
23 ms |
2372 KB |
Output is correct |
58 |
Correct |
23 ms |
2328 KB |
Output is correct |
59 |
Correct |
22 ms |
1628 KB |
Output is correct |
60 |
Correct |
24 ms |
2392 KB |
Output is correct |
61 |
Correct |
26 ms |
2464 KB |
Output is correct |
62 |
Correct |
23 ms |
2396 KB |
Output is correct |
63 |
Correct |
23 ms |
2396 KB |
Output is correct |
64 |
Correct |
22 ms |
2544 KB |
Output is correct |
65 |
Correct |
23 ms |
2392 KB |
Output is correct |
66 |
Correct |
23 ms |
2392 KB |
Output is correct |
67 |
Correct |
22 ms |
2396 KB |
Output is correct |
68 |
Correct |
22 ms |
2452 KB |
Output is correct |
69 |
Correct |
25 ms |
2396 KB |
Output is correct |