#include "bits/stdc++.h"
using namespace std;
#define ar array
typedef long long ll;
#define int ll
const int N = 1e5 + 5;
int x[N];
struct ST{
int mx[N << 2], mn[N << 2];
void set(int i, int v, int lx = 0, int rx = N, int x = 1){
if(lx == rx){
mn[x] = mx[x] = v;
return;
}
int m = (lx + rx) >> 1;
if(i <= m) set(i, v, lx, m, x << 1);
else set(i, v, m + 1, rx, x << 1 | 1);
mn[x] = min(mn[x << 1], mn[x << 1 | 1]);
mx[x] = max(mx[x << 1], mx[x << 1 | 1]);
}
int get_first_big(int l, int r, int v, int lx = 0, int rx = N, int x = 1){
if(lx > r || rx < l) return -1;
if(lx >= l && rx <= r){
if(mx[x] < v) return -1;
if(lx == rx) return lx;
int m = (lx + rx) >> 1;
if(mx[x << 1] >= v) return get_first_big(l, r, v, lx, m, x << 1);
else return get_first_big(l, r, v, m + 1, rx, x << 1 | 1);
} int m = (lx + rx) >> 1;
int res = get_first_big(l, r, v, lx, m, x << 1);
if(res == -1) res = get_first_big(l, r, v, m + 1, rx, x << 1 | 1);
return res;
}
int get_last_low(int l, int r, int v, int lx = 0, int rx = N, int x = 1){
if(lx > r || rx < l) return -1;
if(lx >= l && rx <= r){
if(mn[x] > v) return -1;
if(lx == rx) return lx;
int m = (lx + rx) >> 1;
if(mn[x << 1 | 1] <= v) return get_last_low(l, r, v, m + 1, rx, x << 1 | 1);
else return get_last_low(l, r, v, lx, m, x << 1);
} int m = (lx + rx) >> 1;
int res = get_last_low(l, r, v, m + 1, rx, x << 1 | 1);
if(res == -1) return get_last_low(l, r, v, lx, m, x << 1);
return res;
}
}tree;
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n, k, T; cin >> n >> k >> T;
for(int i=1;i<=n;i++){
cin >> x[i];
}
x[n + 1] = x[n];
tree.set(n + 1, 1e18);
auto check = [&](int s){
int t = T * s * 2;
vector<int> p(n + 1);
for(int i=1;i<=n;i++){
p[i] = x[i] - t * i;
tree.set(i, p[i]);
}
//~ for(int i=1;i<=n;i++){
//~ cout<<p[i]<<" ";
//~ } cout<<"\n";
int pos = tree.get_first_big(k, n + 1, p[k] + 1) - 1;
//~ cout<<pos<<" ";
for(int i=k-1;i>0;i--){
if(p[i] >= p[i + 1]){
pos = tree.get_first_big(pos, n + 1, p[i] + 1) - 1;
} else {
pos = tree.get_last_low(k, pos, p[i]);
if(pos == -1) return false;
}
//~ cout<<pos<<" ";
}
//~ cout<<"\n";
return pos == n;
};
int l = 0, r = x[n] / (T * 2) + 1;
while(l < r){
int m = (l + r) >> 1;
if(check(m)) r = m;
else l = m + 1;
}
cout<<l<<"\n";
}
/*
5 3 1
0 0 3 4 7
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
324 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
456 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
4 ms |
468 KB |
Output is correct |
26 |
Correct |
3 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
460 KB |
Output is correct |
28 |
Correct |
3 ms |
468 KB |
Output is correct |
29 |
Correct |
3 ms |
464 KB |
Output is correct |
30 |
Correct |
3 ms |
468 KB |
Output is correct |
31 |
Correct |
3 ms |
468 KB |
Output is correct |
32 |
Correct |
4 ms |
468 KB |
Output is correct |
33 |
Correct |
3 ms |
468 KB |
Output is correct |
34 |
Correct |
4 ms |
468 KB |
Output is correct |
35 |
Correct |
4 ms |
472 KB |
Output is correct |
36 |
Correct |
2 ms |
468 KB |
Output is correct |
37 |
Correct |
3 ms |
468 KB |
Output is correct |
38 |
Correct |
3 ms |
468 KB |
Output is correct |
39 |
Correct |
3 ms |
468 KB |
Output is correct |
40 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
328 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
324 KB |
Output is correct |
22 |
Correct |
2 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
456 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
4 ms |
468 KB |
Output is correct |
26 |
Correct |
3 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
460 KB |
Output is correct |
28 |
Correct |
3 ms |
468 KB |
Output is correct |
29 |
Correct |
3 ms |
464 KB |
Output is correct |
30 |
Correct |
3 ms |
468 KB |
Output is correct |
31 |
Correct |
3 ms |
468 KB |
Output is correct |
32 |
Correct |
4 ms |
468 KB |
Output is correct |
33 |
Correct |
3 ms |
468 KB |
Output is correct |
34 |
Correct |
4 ms |
468 KB |
Output is correct |
35 |
Correct |
4 ms |
472 KB |
Output is correct |
36 |
Correct |
2 ms |
468 KB |
Output is correct |
37 |
Correct |
3 ms |
468 KB |
Output is correct |
38 |
Correct |
3 ms |
468 KB |
Output is correct |
39 |
Correct |
3 ms |
468 KB |
Output is correct |
40 |
Correct |
1 ms |
468 KB |
Output is correct |
41 |
Correct |
216 ms |
4748 KB |
Output is correct |
42 |
Correct |
5 ms |
588 KB |
Output is correct |
43 |
Correct |
57 ms |
1648 KB |
Output is correct |
44 |
Correct |
257 ms |
6948 KB |
Output is correct |
45 |
Correct |
355 ms |
6968 KB |
Output is correct |
46 |
Correct |
267 ms |
6940 KB |
Output is correct |
47 |
Correct |
291 ms |
6952 KB |
Output is correct |
48 |
Correct |
309 ms |
6948 KB |
Output is correct |
49 |
Correct |
248 ms |
7056 KB |
Output is correct |
50 |
Correct |
334 ms |
6964 KB |
Output is correct |
51 |
Correct |
281 ms |
6984 KB |
Output is correct |
52 |
Correct |
385 ms |
6964 KB |
Output is correct |
53 |
Correct |
259 ms |
7064 KB |
Output is correct |
54 |
Correct |
351 ms |
6944 KB |
Output is correct |
55 |
Correct |
338 ms |
6896 KB |
Output is correct |
56 |
Correct |
257 ms |
6992 KB |
Output is correct |
57 |
Correct |
379 ms |
7032 KB |
Output is correct |
58 |
Correct |
298 ms |
6956 KB |
Output is correct |
59 |
Correct |
19 ms |
6160 KB |
Output is correct |
60 |
Correct |
355 ms |
6948 KB |
Output is correct |
61 |
Correct |
315 ms |
6888 KB |
Output is correct |
62 |
Correct |
261 ms |
6956 KB |
Output is correct |
63 |
Correct |
345 ms |
6868 KB |
Output is correct |
64 |
Correct |
337 ms |
7032 KB |
Output is correct |
65 |
Correct |
294 ms |
6956 KB |
Output is correct |
66 |
Correct |
299 ms |
6952 KB |
Output is correct |
67 |
Correct |
289 ms |
7012 KB |
Output is correct |
68 |
Correct |
338 ms |
7060 KB |
Output is correct |
69 |
Correct |
358 ms |
7000 KB |
Output is correct |