#include "bits/stdc++.h"
using namespace std;
#define ar array
#define int long long
const int inf = 1e9 + 5;
const int N = 1e5 + 5;
struct ST{
int mn[N<<2], mx[N<<2];
void sett(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) sett(i, v, lx, m, x<<1);
else sett(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_rm_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_rm_low(l, r, v, m+1, rx, x<<1|1);
return get_rm_low(l, r, v, lx, m, x<<1);
} int m = (lx + rx) >> 1;
int res = get_rm_low(l, r, v, m+1, rx, x<<1|1);
if(~res) return res;
return get_rm_low(l, r, v, lx, m, x<<1);
}
int get_lm_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_lm_big(l, r, v, lx, m, x<<1);
return get_lm_big(l, r, v, m+1, rx, x<<1|1);
} int m = (lx + rx) >> 1;
int res = get_lm_big(l, r, v, lx, m, x<<1);
if(~res) return res;
return get_lm_big(l, r, v, m+1, rx, x<<1|1);
}
}tree;
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n, k, t; cin>>n>>k>>t;
vector<int> a(n), d(n);
for(int i=0;i<n;i++) cin>>a[i], a[i] *= 2;
for(int i=1;i<n;i++){
d[i] = a[i] - a[i-1];
}
k--;
auto check = [&](int s){
vector<int> b(n);
for(int i=0;i<n;i++) b[i] = a[i] / 2 - i * s * t, tree.sett(i, b[i]);
int pos = tree.get_lm_big(k, n-1, b[k] + 1);
if(pos == -1) pos = n;
pos--;
for(int i=k;i>0;i--){
if(b[i-1] >= b[i]){
pos = tree.get_lm_big(pos, n-1, b[i-1] + 1);
if(pos == -1) pos = n;
pos--;
} else {
pos = tree.get_rm_low(k, pos, b[i-1]);
if(pos == -1){
return false;
}
}
}
return (pos == n - 1);
};
int l = 0, r = 2 * inf;
while(l < r){
int m = (l + r) >> 1;
if(check(m)) r = m;
else l = m + 1;
}
cout<<(l+1) / 2<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 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 |
340 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 |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 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 |
340 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 |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
3 ms |
464 KB |
Output is correct |
26 |
Correct |
3 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
468 KB |
Output is correct |
28 |
Correct |
3 ms |
468 KB |
Output is correct |
29 |
Correct |
4 ms |
468 KB |
Output is correct |
30 |
Correct |
4 ms |
468 KB |
Output is correct |
31 |
Correct |
6 ms |
468 KB |
Output is correct |
32 |
Correct |
5 ms |
468 KB |
Output is correct |
33 |
Correct |
4 ms |
468 KB |
Output is correct |
34 |
Correct |
5 ms |
468 KB |
Output is correct |
35 |
Correct |
4 ms |
468 KB |
Output is correct |
36 |
Correct |
3 ms |
468 KB |
Output is correct |
37 |
Correct |
3 ms |
468 KB |
Output is correct |
38 |
Correct |
4 ms |
464 KB |
Output is correct |
39 |
Correct |
4 ms |
468 KB |
Output is correct |
40 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 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 |
340 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 |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
3 ms |
468 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
3 ms |
464 KB |
Output is correct |
26 |
Correct |
3 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
468 KB |
Output is correct |
28 |
Correct |
3 ms |
468 KB |
Output is correct |
29 |
Correct |
4 ms |
468 KB |
Output is correct |
30 |
Correct |
4 ms |
468 KB |
Output is correct |
31 |
Correct |
6 ms |
468 KB |
Output is correct |
32 |
Correct |
5 ms |
468 KB |
Output is correct |
33 |
Correct |
4 ms |
468 KB |
Output is correct |
34 |
Correct |
5 ms |
468 KB |
Output is correct |
35 |
Correct |
4 ms |
468 KB |
Output is correct |
36 |
Correct |
3 ms |
468 KB |
Output is correct |
37 |
Correct |
3 ms |
468 KB |
Output is correct |
38 |
Correct |
4 ms |
464 KB |
Output is correct |
39 |
Correct |
4 ms |
468 KB |
Output is correct |
40 |
Correct |
3 ms |
468 KB |
Output is correct |
41 |
Correct |
269 ms |
5272 KB |
Output is correct |
42 |
Correct |
6 ms |
596 KB |
Output is correct |
43 |
Correct |
89 ms |
1828 KB |
Output is correct |
44 |
Correct |
292 ms |
7764 KB |
Output is correct |
45 |
Correct |
377 ms |
7752 KB |
Output is correct |
46 |
Correct |
283 ms |
7660 KB |
Output is correct |
47 |
Correct |
302 ms |
7756 KB |
Output is correct |
48 |
Correct |
341 ms |
7748 KB |
Output is correct |
49 |
Correct |
265 ms |
7832 KB |
Output is correct |
50 |
Correct |
373 ms |
7756 KB |
Output is correct |
51 |
Correct |
299 ms |
7756 KB |
Output is correct |
52 |
Correct |
399 ms |
7756 KB |
Output is correct |
53 |
Correct |
306 ms |
7868 KB |
Output is correct |
54 |
Correct |
396 ms |
7752 KB |
Output is correct |
55 |
Correct |
362 ms |
7764 KB |
Output is correct |
56 |
Correct |
307 ms |
7868 KB |
Output is correct |
57 |
Correct |
433 ms |
7768 KB |
Output is correct |
58 |
Correct |
353 ms |
7860 KB |
Output is correct |
59 |
Correct |
394 ms |
6980 KB |
Output is correct |
60 |
Correct |
445 ms |
7752 KB |
Output is correct |
61 |
Correct |
378 ms |
7672 KB |
Output is correct |
62 |
Correct |
297 ms |
7668 KB |
Output is correct |
63 |
Correct |
383 ms |
7744 KB |
Output is correct |
64 |
Correct |
410 ms |
7756 KB |
Output is correct |
65 |
Correct |
353 ms |
7748 KB |
Output is correct |
66 |
Correct |
364 ms |
7728 KB |
Output is correct |
67 |
Correct |
323 ms |
7740 KB |
Output is correct |
68 |
Correct |
404 ms |
7740 KB |
Output is correct |
69 |
Correct |
433 ms |
7736 KB |
Output is correct |