from bisect import *
n,x = map(int, input().split())
arr = list(map(int, input().split()))
arrneg = [-i for i in arr]
arrneg.reverse()
dp = [0 for i in range(n)]
dp2 = [0 for i in range(n)]
lis = []
for j in range(len(arr)):
i = arr[j]
sus = bisect_left(lis,i)
dp[j] = sus+1
if sus==len(lis):
lis.append(i)
else:
lis[sus] = i
lis = []
for j in range(len(arrneg)):
i = arrneg[j]
sus = bisect_left(lis,i)
sussy = bisect_left(lis,i+x)
dp2[j] = sussy+1
if sus==len(lis):
lis.append(i)
else:
lis[sus] = i
dp2.reverse()
maxi = 0
for i in range(len(dp)):
maxi = max(maxi, dp[i]+dp2[i]-1)
print(maxi)
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
18168 KB |
Output is correct |
2 |
Correct |
33 ms |
18192 KB |
Output is correct |
3 |
Correct |
35 ms |
18196 KB |
Output is correct |
4 |
Correct |
33 ms |
18188 KB |
Output is correct |
5 |
Correct |
33 ms |
18180 KB |
Output is correct |
6 |
Correct |
37 ms |
18216 KB |
Output is correct |
7 |
Correct |
34 ms |
18188 KB |
Output is correct |
8 |
Correct |
34 ms |
18132 KB |
Output is correct |
9 |
Correct |
37 ms |
18204 KB |
Output is correct |
10 |
Correct |
33 ms |
18208 KB |
Output is correct |
11 |
Correct |
36 ms |
18188 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
18168 KB |
Output is correct |
2 |
Correct |
33 ms |
18192 KB |
Output is correct |
3 |
Correct |
35 ms |
18196 KB |
Output is correct |
4 |
Correct |
33 ms |
18188 KB |
Output is correct |
5 |
Correct |
33 ms |
18180 KB |
Output is correct |
6 |
Correct |
37 ms |
18216 KB |
Output is correct |
7 |
Correct |
34 ms |
18188 KB |
Output is correct |
8 |
Correct |
34 ms |
18132 KB |
Output is correct |
9 |
Correct |
37 ms |
18204 KB |
Output is correct |
10 |
Correct |
33 ms |
18208 KB |
Output is correct |
11 |
Correct |
36 ms |
18188 KB |
Output is correct |
12 |
Correct |
34 ms |
18228 KB |
Output is correct |
13 |
Correct |
34 ms |
18208 KB |
Output is correct |
14 |
Correct |
33 ms |
18200 KB |
Output is correct |
15 |
Correct |
35 ms |
18240 KB |
Output is correct |
16 |
Correct |
35 ms |
18200 KB |
Output is correct |
17 |
Correct |
35 ms |
18220 KB |
Output is correct |
18 |
Correct |
34 ms |
18184 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
18168 KB |
Output is correct |
2 |
Correct |
33 ms |
18192 KB |
Output is correct |
3 |
Correct |
35 ms |
18196 KB |
Output is correct |
4 |
Correct |
33 ms |
18188 KB |
Output is correct |
5 |
Correct |
33 ms |
18180 KB |
Output is correct |
6 |
Correct |
37 ms |
18216 KB |
Output is correct |
7 |
Correct |
34 ms |
18188 KB |
Output is correct |
8 |
Correct |
34 ms |
18132 KB |
Output is correct |
9 |
Correct |
37 ms |
18204 KB |
Output is correct |
10 |
Correct |
33 ms |
18208 KB |
Output is correct |
11 |
Correct |
36 ms |
18188 KB |
Output is correct |
12 |
Correct |
34 ms |
18228 KB |
Output is correct |
13 |
Correct |
34 ms |
18208 KB |
Output is correct |
14 |
Correct |
33 ms |
18200 KB |
Output is correct |
15 |
Correct |
35 ms |
18240 KB |
Output is correct |
16 |
Correct |
35 ms |
18200 KB |
Output is correct |
17 |
Correct |
35 ms |
18220 KB |
Output is correct |
18 |
Correct |
34 ms |
18184 KB |
Output is correct |
19 |
Correct |
46 ms |
18968 KB |
Output is correct |
20 |
Correct |
52 ms |
18948 KB |
Output is correct |
21 |
Correct |
47 ms |
18972 KB |
Output is correct |
22 |
Correct |
45 ms |
18984 KB |
Output is correct |
23 |
Correct |
47 ms |
18808 KB |
Output is correct |
24 |
Correct |
47 ms |
19144 KB |
Output is correct |
25 |
Correct |
45 ms |
18984 KB |
Output is correct |
26 |
Correct |
48 ms |
19044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
200 ms |
47244 KB |
Output is correct |
2 |
Correct |
201 ms |
45556 KB |
Output is correct |
3 |
Correct |
210 ms |
47380 KB |
Output is correct |
4 |
Correct |
202 ms |
47216 KB |
Output is correct |
5 |
Correct |
230 ms |
42536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
106 ms |
26120 KB |
Output is correct |
2 |
Correct |
104 ms |
25884 KB |
Output is correct |
3 |
Correct |
104 ms |
26124 KB |
Output is correct |
4 |
Correct |
87 ms |
25976 KB |
Output is correct |
5 |
Correct |
34 ms |
18224 KB |
Output is correct |
6 |
Correct |
94 ms |
25924 KB |
Output is correct |
7 |
Correct |
107 ms |
25764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
142 ms |
30880 KB |
Output is correct |
2 |
Correct |
129 ms |
30964 KB |
Output is correct |
3 |
Correct |
210 ms |
47232 KB |
Output is correct |
4 |
Correct |
177 ms |
43212 KB |
Output is correct |
5 |
Correct |
133 ms |
30984 KB |
Output is correct |
6 |
Correct |
174 ms |
43940 KB |
Output is correct |
7 |
Correct |
178 ms |
45320 KB |
Output is correct |
8 |
Correct |
145 ms |
30080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
18168 KB |
Output is correct |
2 |
Correct |
33 ms |
18192 KB |
Output is correct |
3 |
Correct |
35 ms |
18196 KB |
Output is correct |
4 |
Correct |
33 ms |
18188 KB |
Output is correct |
5 |
Correct |
33 ms |
18180 KB |
Output is correct |
6 |
Correct |
37 ms |
18216 KB |
Output is correct |
7 |
Correct |
34 ms |
18188 KB |
Output is correct |
8 |
Correct |
34 ms |
18132 KB |
Output is correct |
9 |
Correct |
37 ms |
18204 KB |
Output is correct |
10 |
Correct |
33 ms |
18208 KB |
Output is correct |
11 |
Correct |
36 ms |
18188 KB |
Output is correct |
12 |
Correct |
34 ms |
18228 KB |
Output is correct |
13 |
Correct |
34 ms |
18208 KB |
Output is correct |
14 |
Correct |
33 ms |
18200 KB |
Output is correct |
15 |
Correct |
35 ms |
18240 KB |
Output is correct |
16 |
Correct |
35 ms |
18200 KB |
Output is correct |
17 |
Correct |
35 ms |
18220 KB |
Output is correct |
18 |
Correct |
34 ms |
18184 KB |
Output is correct |
19 |
Correct |
46 ms |
18968 KB |
Output is correct |
20 |
Correct |
52 ms |
18948 KB |
Output is correct |
21 |
Correct |
47 ms |
18972 KB |
Output is correct |
22 |
Correct |
45 ms |
18984 KB |
Output is correct |
23 |
Correct |
47 ms |
18808 KB |
Output is correct |
24 |
Correct |
47 ms |
19144 KB |
Output is correct |
25 |
Correct |
45 ms |
18984 KB |
Output is correct |
26 |
Correct |
48 ms |
19044 KB |
Output is correct |
27 |
Correct |
200 ms |
47244 KB |
Output is correct |
28 |
Correct |
201 ms |
45556 KB |
Output is correct |
29 |
Correct |
210 ms |
47380 KB |
Output is correct |
30 |
Correct |
202 ms |
47216 KB |
Output is correct |
31 |
Correct |
230 ms |
42536 KB |
Output is correct |
32 |
Correct |
106 ms |
26120 KB |
Output is correct |
33 |
Correct |
104 ms |
25884 KB |
Output is correct |
34 |
Correct |
104 ms |
26124 KB |
Output is correct |
35 |
Correct |
87 ms |
25976 KB |
Output is correct |
36 |
Correct |
34 ms |
18224 KB |
Output is correct |
37 |
Correct |
94 ms |
25924 KB |
Output is correct |
38 |
Correct |
107 ms |
25764 KB |
Output is correct |
39 |
Correct |
142 ms |
30880 KB |
Output is correct |
40 |
Correct |
129 ms |
30964 KB |
Output is correct |
41 |
Correct |
210 ms |
47232 KB |
Output is correct |
42 |
Correct |
177 ms |
43212 KB |
Output is correct |
43 |
Correct |
133 ms |
30984 KB |
Output is correct |
44 |
Correct |
174 ms |
43940 KB |
Output is correct |
45 |
Correct |
178 ms |
45320 KB |
Output is correct |
46 |
Correct |
145 ms |
30080 KB |
Output is correct |
47 |
Correct |
147 ms |
30900 KB |
Output is correct |
48 |
Correct |
132 ms |
30852 KB |
Output is correct |
49 |
Correct |
205 ms |
45632 KB |
Output is correct |
50 |
Correct |
204 ms |
42556 KB |
Output is correct |
51 |
Correct |
150 ms |
37004 KB |
Output is correct |
52 |
Correct |
210 ms |
41752 KB |
Output is correct |
53 |
Correct |
191 ms |
41852 KB |
Output is correct |
54 |
Correct |
182 ms |
45636 KB |
Output is correct |
55 |
Correct |
195 ms |
45564 KB |
Output is correct |