#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 10;
int n, k, t;
int a[N];
long long x[N];
set<long long> L, R;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k >> t;
for(int i = 1; i <= n; i++) cin >> a[i];
int l = 0, r = 1e9;
int ans = r;
while(l <= r) {
int mid = (l + r) / 2;
if(2LL * mid * t > 1e9) {
ans = mid;
r = mid - 1;
continue;
}
for(int i = 1; i <= n; i++) x[i] = a[i] - 2LL * mid * i * t;
L.clear();
R.clear();
L.insert(x[k]);
R.insert(x[k]);
int i = k, j = k;
while(true) {
int change = 0;
auto it = R.begin();
if(i > 1) it = R.upper_bound(x[i - 1]);
while(i > 1 && it != R.begin()) {
change++;
i--;
L.insert(x[i]);
if(i > 1) it = R.upper_bound(x[i - 1]);
}
if(j < n) it = L.lower_bound(x[j + 1]);
while(j < n && it != L.end()) {
change++;
j++;
R.insert(x[j]);
if(j < n) it = L.lower_bound(x[j + 1]);
}
if(change == 0) break;
}
if(i != 1 || j != n) {
l = mid + 1;
continue;
}
L.clear();
R.clear();
L.insert(x[1]);
R.insert(x[n]);
if(x[1] < x[n]) {
l = mid + 1;
continue;
}
i = 1, j = n;
while(true) {
int change = 0;
auto it = R.begin();
if(i < k) it = R.upper_bound(x[i + 1]);
while(i < k && it != R.begin()) {
change++;
i++;
L.insert(x[i]);
if(i < k) it = R.upper_bound(x[i + 1]);
}
if(j > k) it = L.lower_bound(x[j - 1]);
while(j > k && it != L.end()) {
change++;
j--;
R.insert(x[j]);
if(j > k) it = L.lower_bound(x[j - 1]);
}
if(change == 0) break;
}
if(i != k || j != k) {
l = mid + 1;
continue;
}
ans = mid;
r = mid - 1;
}
cout << ans;
return 0;
}
# |
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 |
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 |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 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 |
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 |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
3 ms |
344 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
4 ms |
348 KB |
Output is correct |
26 |
Correct |
4 ms |
348 KB |
Output is correct |
27 |
Correct |
5 ms |
544 KB |
Output is correct |
28 |
Correct |
3 ms |
348 KB |
Output is correct |
29 |
Correct |
3 ms |
348 KB |
Output is correct |
30 |
Correct |
3 ms |
348 KB |
Output is correct |
31 |
Correct |
3 ms |
348 KB |
Output is correct |
32 |
Correct |
5 ms |
344 KB |
Output is correct |
33 |
Correct |
5 ms |
344 KB |
Output is correct |
34 |
Correct |
4 ms |
344 KB |
Output is correct |
35 |
Correct |
5 ms |
540 KB |
Output is correct |
36 |
Correct |
3 ms |
344 KB |
Output is correct |
37 |
Correct |
5 ms |
348 KB |
Output is correct |
38 |
Correct |
4 ms |
540 KB |
Output is correct |
39 |
Correct |
5 ms |
344 KB |
Output is correct |
40 |
Correct |
6 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 |
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 |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
3 ms |
344 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
2 ms |
348 KB |
Output is correct |
25 |
Correct |
4 ms |
348 KB |
Output is correct |
26 |
Correct |
4 ms |
348 KB |
Output is correct |
27 |
Correct |
5 ms |
544 KB |
Output is correct |
28 |
Correct |
3 ms |
348 KB |
Output is correct |
29 |
Correct |
3 ms |
348 KB |
Output is correct |
30 |
Correct |
3 ms |
348 KB |
Output is correct |
31 |
Correct |
3 ms |
348 KB |
Output is correct |
32 |
Correct |
5 ms |
344 KB |
Output is correct |
33 |
Correct |
5 ms |
344 KB |
Output is correct |
34 |
Correct |
4 ms |
344 KB |
Output is correct |
35 |
Correct |
5 ms |
540 KB |
Output is correct |
36 |
Correct |
3 ms |
344 KB |
Output is correct |
37 |
Correct |
5 ms |
348 KB |
Output is correct |
38 |
Correct |
4 ms |
540 KB |
Output is correct |
39 |
Correct |
5 ms |
344 KB |
Output is correct |
40 |
Correct |
6 ms |
348 KB |
Output is correct |
41 |
Correct |
394 ms |
4964 KB |
Output is correct |
42 |
Correct |
9 ms |
604 KB |
Output is correct |
43 |
Correct |
73 ms |
1628 KB |
Output is correct |
44 |
Correct |
649 ms |
7596 KB |
Output is correct |
45 |
Correct |
584 ms |
7660 KB |
Output is correct |
46 |
Correct |
749 ms |
7508 KB |
Output is correct |
47 |
Correct |
749 ms |
7656 KB |
Output is correct |
48 |
Correct |
679 ms |
7652 KB |
Output is correct |
49 |
Correct |
681 ms |
7660 KB |
Output is correct |
50 |
Correct |
563 ms |
7664 KB |
Output is correct |
51 |
Correct |
770 ms |
7660 KB |
Output is correct |
52 |
Correct |
521 ms |
7664 KB |
Output is correct |
53 |
Correct |
796 ms |
7664 KB |
Output is correct |
54 |
Correct |
524 ms |
7664 KB |
Output is correct |
55 |
Correct |
625 ms |
7668 KB |
Output is correct |
56 |
Correct |
581 ms |
7652 KB |
Output is correct |
57 |
Correct |
616 ms |
7764 KB |
Output is correct |
58 |
Correct |
584 ms |
7656 KB |
Output is correct |
59 |
Correct |
704 ms |
6896 KB |
Output is correct |
60 |
Correct |
825 ms |
7660 KB |
Output is correct |
61 |
Correct |
625 ms |
7580 KB |
Output is correct |
62 |
Correct |
840 ms |
7664 KB |
Output is correct |
63 |
Correct |
735 ms |
7656 KB |
Output is correct |
64 |
Correct |
754 ms |
7764 KB |
Output is correct |
65 |
Correct |
704 ms |
7764 KB |
Output is correct |
66 |
Correct |
640 ms |
7632 KB |
Output is correct |
67 |
Correct |
621 ms |
7656 KB |
Output is correct |
68 |
Correct |
600 ms |
7760 KB |
Output is correct |
69 |
Correct |
532 ms |
7644 KB |
Output is correct |