#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N, K, T, A[100005], B[100005];
bool f(ll v){
for(ll i = 1; i <= N; i++){
B[i] = A[i] - 2 * v * T * i;
}
ll gl = K, gr = K;
for(ll i = 1; i <= N; i++){
if(i <= K && B[gl] <= B[i]) gl = i;
if(i >= K && B[gr] >= B[i]) gr = i;
}
ll l = K, r = K;
while(1){
ll ch = 0, nl = l, nr = r;
while(nl > gl && B[nl - 1] >= B[r] && (nl == l || B[nl] < B[l])) nl--;
if(B[nl] >= B[l] && nl < l){
l = nl, ch = 1;
}
while(nr < gr && B[nr + 1] <= B[l] && (nr == r || B[nr] > B[r])) nr++;
if(B[nr] <= B[r] && nr > r){
r = nr, ch = 1;
}
if(ch == 0) break;
}
if(l != gl || r != gr) return 0;
l = 1, r = N;
if(B[l] < B[r]) return 0;
while(1){
ll ch = 0, nl = l, nr = r;
while(nl < gl && B[nl + 1] >= B[r] && (nl == l || B[nl] < B[l])) nl++;
if(B[nl] >= B[l] && nl > l){
l = nl, ch = 1;
}
while(nr > gr && B[nr - 1] <= B[l] && (nr == r || B[nr] > B[r])) nr--;
if(B[nr] <= B[r] && nr < r){
r = nr, ch = 1;
}
if(ch == 0) break;
}
return (l == gl && r == gr);
}
int main(){
cin.tie(0) -> sync_with_stdio(0);
cin >> N >> K >> T;
for(ll i = 1; i <= N; i++){
cin >> A[i];
}
if(A[N] == 0){
cout << 0; return 0;
}
ll L = 1, R = 1e9;
while(L <= R){
ll m = (L + R) / 2;
if(f(m)) R = m - 1;
else L = m + 1;
}
cout << L;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 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 |
0 ms |
464 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 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 |
1 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 |
348 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 |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 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 |
0 ms |
464 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
480 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 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 |
0 ms |
464 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
1 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
480 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
344 KB |
Output is correct |
41 |
Correct |
20 ms |
2140 KB |
Output is correct |
42 |
Correct |
1 ms |
480 KB |
Output is correct |
43 |
Correct |
5 ms |
744 KB |
Output is correct |
44 |
Correct |
27 ms |
2912 KB |
Output is correct |
45 |
Correct |
22 ms |
2912 KB |
Output is correct |
46 |
Correct |
22 ms |
2908 KB |
Output is correct |
47 |
Correct |
25 ms |
2912 KB |
Output is correct |
48 |
Correct |
23 ms |
2908 KB |
Output is correct |
49 |
Correct |
23 ms |
2908 KB |
Output is correct |
50 |
Correct |
22 ms |
2900 KB |
Output is correct |
51 |
Correct |
25 ms |
2908 KB |
Output is correct |
52 |
Correct |
22 ms |
2908 KB |
Output is correct |
53 |
Correct |
24 ms |
2940 KB |
Output is correct |
54 |
Correct |
28 ms |
2932 KB |
Output is correct |
55 |
Correct |
24 ms |
2904 KB |
Output is correct |
56 |
Correct |
23 ms |
2908 KB |
Output is correct |
57 |
Correct |
22 ms |
2908 KB |
Output is correct |
58 |
Correct |
23 ms |
2908 KB |
Output is correct |
59 |
Correct |
4 ms |
1368 KB |
Output is correct |
60 |
Correct |
21 ms |
2980 KB |
Output is correct |
61 |
Correct |
21 ms |
2908 KB |
Output is correct |
62 |
Correct |
22 ms |
2908 KB |
Output is correct |
63 |
Correct |
21 ms |
2904 KB |
Output is correct |
64 |
Correct |
24 ms |
3052 KB |
Output is correct |
65 |
Correct |
22 ms |
2904 KB |
Output is correct |
66 |
Correct |
22 ms |
2908 KB |
Output is correct |
67 |
Correct |
21 ms |
2904 KB |
Output is correct |
68 |
Correct |
21 ms |
2908 KB |
Output is correct |
69 |
Correct |
26 ms |
2732 KB |
Output is correct |