#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
int n, x, hely, cur, ans = 0;
cin >> n >> x;
vector <int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
vector <int> suf(n);
vector <int> dp(n + 1);
fill(dp.begin(), dp.end(), 2e9);
dp[0] = -2e9;
for (int i = n - 1; i >= 0; i--) {
hely = lower_bound(dp.begin(), dp.end(), -v[i]) - dp.begin();
suf[i] = hely;
dp[hely] = -v[i];
}
fill(dp.begin(), dp.end(), 2e9);
dp[0] = -2e9;
for (int i = 0; i < n; i++) {
cur = lower_bound(dp.begin(), dp.end(), v[i] + x) - dp.begin() - 1 + suf[i];
ans = max(ans, cur);
hely = lower_bound(dp.begin(), dp.end(), v[i]) - dp.begin();
suf[i] = hely;
dp[hely] = v[i];
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
300 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
300 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
300 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
300 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
300 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
4512 KB |
Output is correct |
2 |
Correct |
105 ms |
4512 KB |
Output is correct |
3 |
Correct |
104 ms |
4572 KB |
Output is correct |
4 |
Correct |
105 ms |
4524 KB |
Output is correct |
5 |
Correct |
69 ms |
3744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
1372 KB |
Output is correct |
2 |
Correct |
25 ms |
1372 KB |
Output is correct |
3 |
Correct |
27 ms |
1368 KB |
Output is correct |
4 |
Correct |
19 ms |
1080 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
18 ms |
1168 KB |
Output is correct |
7 |
Correct |
25 ms |
1380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
2352 KB |
Output is correct |
2 |
Correct |
49 ms |
2436 KB |
Output is correct |
3 |
Correct |
98 ms |
4556 KB |
Output is correct |
4 |
Correct |
73 ms |
3744 KB |
Output is correct |
5 |
Correct |
36 ms |
1980 KB |
Output is correct |
6 |
Correct |
66 ms |
3632 KB |
Output is correct |
7 |
Correct |
84 ms |
4348 KB |
Output is correct |
8 |
Correct |
46 ms |
2444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
300 KB |
Output is correct |
10 |
Correct |
1 ms |
296 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
300 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
110 ms |
4512 KB |
Output is correct |
28 |
Correct |
105 ms |
4512 KB |
Output is correct |
29 |
Correct |
104 ms |
4572 KB |
Output is correct |
30 |
Correct |
105 ms |
4524 KB |
Output is correct |
31 |
Correct |
69 ms |
3744 KB |
Output is correct |
32 |
Correct |
25 ms |
1372 KB |
Output is correct |
33 |
Correct |
25 ms |
1372 KB |
Output is correct |
34 |
Correct |
27 ms |
1368 KB |
Output is correct |
35 |
Correct |
19 ms |
1080 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
18 ms |
1168 KB |
Output is correct |
38 |
Correct |
25 ms |
1380 KB |
Output is correct |
39 |
Correct |
50 ms |
2352 KB |
Output is correct |
40 |
Correct |
49 ms |
2436 KB |
Output is correct |
41 |
Correct |
98 ms |
4556 KB |
Output is correct |
42 |
Correct |
73 ms |
3744 KB |
Output is correct |
43 |
Correct |
36 ms |
1980 KB |
Output is correct |
44 |
Correct |
66 ms |
3632 KB |
Output is correct |
45 |
Correct |
84 ms |
4348 KB |
Output is correct |
46 |
Correct |
46 ms |
2444 KB |
Output is correct |
47 |
Correct |
54 ms |
2380 KB |
Output is correct |
48 |
Correct |
56 ms |
2336 KB |
Output is correct |
49 |
Correct |
114 ms |
4568 KB |
Output is correct |
50 |
Correct |
75 ms |
3752 KB |
Output is correct |
51 |
Correct |
56 ms |
2892 KB |
Output is correct |
52 |
Correct |
76 ms |
3788 KB |
Output is correct |
53 |
Correct |
70 ms |
3788 KB |
Output is correct |
54 |
Correct |
92 ms |
4520 KB |
Output is correct |
55 |
Correct |
97 ms |
4512 KB |
Output is correct |