#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1, mod = 1e9 + 7;
int n, x, ans = 0, a[N], f[2][N];
int main() {
cin.tie(0) -> sync_with_stdio(0);
cin >> n >> x;
for (int i = 1; i <= n; i++) {
cin >> a[i];
f[0][i] = f[1][i] = INT_MAX;
}
f[0][0] = f[1][0] = -INT_MAX;
for (int i = 2; i <= n; i++) {
int k = lower_bound(f[0] + 1, f[0] + n + 1, a[i - 1] - x) - f[0];
f[0][k] = a[i - 1] - x;
f[1][k] = min(f[1][k], f[0][k]);
ans = max(ans, k);
k = lower_bound(f[1] + 1, f[1] + n + 1, a[i]) - f[1];
f[1][k] = a[i];
ans = max(ans, k);
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
4480 KB |
Output is correct |
2 |
Correct |
36 ms |
4576 KB |
Output is correct |
3 |
Correct |
36 ms |
4556 KB |
Output is correct |
4 |
Correct |
38 ms |
4556 KB |
Output is correct |
5 |
Correct |
26 ms |
3796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
1368 KB |
Output is correct |
2 |
Correct |
9 ms |
1404 KB |
Output is correct |
3 |
Correct |
9 ms |
1392 KB |
Output is correct |
4 |
Correct |
7 ms |
1108 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
7 ms |
1108 KB |
Output is correct |
7 |
Correct |
8 ms |
1364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
2460 KB |
Output is correct |
2 |
Correct |
19 ms |
2372 KB |
Output is correct |
3 |
Correct |
39 ms |
4564 KB |
Output is correct |
4 |
Correct |
28 ms |
3760 KB |
Output is correct |
5 |
Correct |
14 ms |
2088 KB |
Output is correct |
6 |
Correct |
26 ms |
3668 KB |
Output is correct |
7 |
Correct |
27 ms |
4404 KB |
Output is correct |
8 |
Correct |
16 ms |
2468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
37 ms |
4480 KB |
Output is correct |
28 |
Correct |
36 ms |
4576 KB |
Output is correct |
29 |
Correct |
36 ms |
4556 KB |
Output is correct |
30 |
Correct |
38 ms |
4556 KB |
Output is correct |
31 |
Correct |
26 ms |
3796 KB |
Output is correct |
32 |
Correct |
9 ms |
1368 KB |
Output is correct |
33 |
Correct |
9 ms |
1404 KB |
Output is correct |
34 |
Correct |
9 ms |
1392 KB |
Output is correct |
35 |
Correct |
7 ms |
1108 KB |
Output is correct |
36 |
Correct |
0 ms |
340 KB |
Output is correct |
37 |
Correct |
7 ms |
1108 KB |
Output is correct |
38 |
Correct |
8 ms |
1364 KB |
Output is correct |
39 |
Correct |
19 ms |
2460 KB |
Output is correct |
40 |
Correct |
19 ms |
2372 KB |
Output is correct |
41 |
Correct |
39 ms |
4564 KB |
Output is correct |
42 |
Correct |
28 ms |
3760 KB |
Output is correct |
43 |
Correct |
14 ms |
2088 KB |
Output is correct |
44 |
Correct |
26 ms |
3668 KB |
Output is correct |
45 |
Correct |
27 ms |
4404 KB |
Output is correct |
46 |
Correct |
16 ms |
2468 KB |
Output is correct |
47 |
Correct |
18 ms |
2472 KB |
Output is correct |
48 |
Correct |
19 ms |
2412 KB |
Output is correct |
49 |
Correct |
37 ms |
4452 KB |
Output is correct |
50 |
Correct |
26 ms |
3768 KB |
Output is correct |
51 |
Correct |
23 ms |
2936 KB |
Output is correct |
52 |
Correct |
28 ms |
3928 KB |
Output is correct |
53 |
Correct |
24 ms |
3884 KB |
Output is correct |
54 |
Correct |
31 ms |
4668 KB |
Output is correct |
55 |
Correct |
37 ms |
4604 KB |
Output is correct |