#include <iostream>
#include <vector>
using namespace std;
const int NMAX = 2e5;
int n,x;
int V[NMAX + 5];
vector<int> L_PREF[NMAX + 5];
int len_pref;
vector<int> L_SUFF[NMAX + 5];
int len_suff;
int ans = 0;
int dp_pref[NMAX + 5];
int main() {
cin >> n >> x;
for(int i = 1;i <= n;i++){
cin >> V[i];
}
V[0] = -(1 << 30);
V[n + 1] = 1 << 30;
L_PREF[0].push_back(0);
len_pref = 0;
for(int i = 1;i <= n;i++){
int st = 0,dr = len_pref + 1;
while(dr - st > 1){
int mid = (st + dr) / 2;
if(V[L_PREF[mid].back()] < V[i]){
st = mid;
}
else{
dr = mid;
}
}
dp_pref[i] = st + 1;
if(st == len_pref){
len_pref++;
L_PREF[len_pref].push_back(i);
}
else{
L_PREF[st + 1].push_back(i);
}
}
ans = len_pref;
L_SUFF[0].push_back(n + 1);
len_suff = 0;
for(int i = n;i;i--){
int st = 0,dr = len_suff + 1;
while(dr - st > 1){
int mid = (st + dr) / 2;
if(V[L_SUFF[mid].back()] > V[i]){
st = mid;
}
else{
dr = mid;
}
}
if(st == len_suff){
len_suff++;
L_SUFF[len_suff].push_back(i);
}
else{
L_SUFF[st + 1].push_back(i);
}
L_PREF[dp_pref[i]].pop_back();
while(L_PREF[len_pref].empty()){
len_pref--;
}
int st2 = 0,dr2 = len_pref + 1;
while(dr2 - st2 > 1){
int mid = (st2 + dr2) / 2;
if(V[L_PREF[mid].back()] < V[i] + x){
st2 = mid;
}
else{
dr2 = mid;
}
}
ans = max(ans,st2 + st + 1);
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
9720 KB |
Output is correct |
2 |
Correct |
12 ms |
9836 KB |
Output is correct |
3 |
Correct |
11 ms |
9836 KB |
Output is correct |
4 |
Correct |
14 ms |
9836 KB |
Output is correct |
5 |
Correct |
12 ms |
9836 KB |
Output is correct |
6 |
Correct |
14 ms |
9836 KB |
Output is correct |
7 |
Correct |
12 ms |
9964 KB |
Output is correct |
8 |
Correct |
13 ms |
9964 KB |
Output is correct |
9 |
Correct |
12 ms |
9964 KB |
Output is correct |
10 |
Correct |
10 ms |
9964 KB |
Output is correct |
11 |
Correct |
12 ms |
9964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
9720 KB |
Output is correct |
2 |
Correct |
12 ms |
9836 KB |
Output is correct |
3 |
Correct |
11 ms |
9836 KB |
Output is correct |
4 |
Correct |
14 ms |
9836 KB |
Output is correct |
5 |
Correct |
12 ms |
9836 KB |
Output is correct |
6 |
Correct |
14 ms |
9836 KB |
Output is correct |
7 |
Correct |
12 ms |
9964 KB |
Output is correct |
8 |
Correct |
13 ms |
9964 KB |
Output is correct |
9 |
Correct |
12 ms |
9964 KB |
Output is correct |
10 |
Correct |
10 ms |
9964 KB |
Output is correct |
11 |
Correct |
12 ms |
9964 KB |
Output is correct |
12 |
Correct |
11 ms |
9984 KB |
Output is correct |
13 |
Correct |
13 ms |
9984 KB |
Output is correct |
14 |
Correct |
13 ms |
9992 KB |
Output is correct |
15 |
Correct |
12 ms |
9992 KB |
Output is correct |
16 |
Correct |
13 ms |
10064 KB |
Output is correct |
17 |
Correct |
13 ms |
10064 KB |
Output is correct |
18 |
Correct |
12 ms |
10068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
9720 KB |
Output is correct |
2 |
Correct |
12 ms |
9836 KB |
Output is correct |
3 |
Correct |
11 ms |
9836 KB |
Output is correct |
4 |
Correct |
14 ms |
9836 KB |
Output is correct |
5 |
Correct |
12 ms |
9836 KB |
Output is correct |
6 |
Correct |
14 ms |
9836 KB |
Output is correct |
7 |
Correct |
12 ms |
9964 KB |
Output is correct |
8 |
Correct |
13 ms |
9964 KB |
Output is correct |
9 |
Correct |
12 ms |
9964 KB |
Output is correct |
10 |
Correct |
10 ms |
9964 KB |
Output is correct |
11 |
Correct |
12 ms |
9964 KB |
Output is correct |
12 |
Correct |
11 ms |
9984 KB |
Output is correct |
13 |
Correct |
13 ms |
9984 KB |
Output is correct |
14 |
Correct |
13 ms |
9992 KB |
Output is correct |
15 |
Correct |
12 ms |
9992 KB |
Output is correct |
16 |
Correct |
13 ms |
10064 KB |
Output is correct |
17 |
Correct |
13 ms |
10064 KB |
Output is correct |
18 |
Correct |
12 ms |
10068 KB |
Output is correct |
19 |
Correct |
13 ms |
10068 KB |
Output is correct |
20 |
Correct |
16 ms |
10068 KB |
Output is correct |
21 |
Correct |
13 ms |
10068 KB |
Output is correct |
22 |
Correct |
13 ms |
10068 KB |
Output is correct |
23 |
Correct |
13 ms |
10068 KB |
Output is correct |
24 |
Correct |
12 ms |
10068 KB |
Output is correct |
25 |
Correct |
12 ms |
10068 KB |
Output is correct |
26 |
Correct |
12 ms |
10068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
200 ms |
14104 KB |
Output is correct |
2 |
Correct |
222 ms |
14104 KB |
Output is correct |
3 |
Correct |
193 ms |
14104 KB |
Output is correct |
4 |
Correct |
240 ms |
14104 KB |
Output is correct |
5 |
Correct |
384 ms |
18364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
18364 KB |
Output is correct |
2 |
Correct |
65 ms |
18364 KB |
Output is correct |
3 |
Correct |
58 ms |
18364 KB |
Output is correct |
4 |
Correct |
78 ms |
18364 KB |
Output is correct |
5 |
Correct |
11 ms |
18364 KB |
Output is correct |
6 |
Correct |
78 ms |
18364 KB |
Output is correct |
7 |
Correct |
58 ms |
18364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
114 ms |
18364 KB |
Output is correct |
2 |
Correct |
98 ms |
18364 KB |
Output is correct |
3 |
Correct |
182 ms |
18364 KB |
Output is correct |
4 |
Correct |
352 ms |
18364 KB |
Output is correct |
5 |
Correct |
163 ms |
18364 KB |
Output is correct |
6 |
Correct |
278 ms |
18364 KB |
Output is correct |
7 |
Correct |
289 ms |
18600 KB |
Output is correct |
8 |
Correct |
111 ms |
18600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
9720 KB |
Output is correct |
2 |
Correct |
12 ms |
9836 KB |
Output is correct |
3 |
Correct |
11 ms |
9836 KB |
Output is correct |
4 |
Correct |
14 ms |
9836 KB |
Output is correct |
5 |
Correct |
12 ms |
9836 KB |
Output is correct |
6 |
Correct |
14 ms |
9836 KB |
Output is correct |
7 |
Correct |
12 ms |
9964 KB |
Output is correct |
8 |
Correct |
13 ms |
9964 KB |
Output is correct |
9 |
Correct |
12 ms |
9964 KB |
Output is correct |
10 |
Correct |
10 ms |
9964 KB |
Output is correct |
11 |
Correct |
12 ms |
9964 KB |
Output is correct |
12 |
Correct |
11 ms |
9984 KB |
Output is correct |
13 |
Correct |
13 ms |
9984 KB |
Output is correct |
14 |
Correct |
13 ms |
9992 KB |
Output is correct |
15 |
Correct |
12 ms |
9992 KB |
Output is correct |
16 |
Correct |
13 ms |
10064 KB |
Output is correct |
17 |
Correct |
13 ms |
10064 KB |
Output is correct |
18 |
Correct |
12 ms |
10068 KB |
Output is correct |
19 |
Correct |
13 ms |
10068 KB |
Output is correct |
20 |
Correct |
16 ms |
10068 KB |
Output is correct |
21 |
Correct |
13 ms |
10068 KB |
Output is correct |
22 |
Correct |
13 ms |
10068 KB |
Output is correct |
23 |
Correct |
13 ms |
10068 KB |
Output is correct |
24 |
Correct |
12 ms |
10068 KB |
Output is correct |
25 |
Correct |
12 ms |
10068 KB |
Output is correct |
26 |
Correct |
12 ms |
10068 KB |
Output is correct |
27 |
Correct |
200 ms |
14104 KB |
Output is correct |
28 |
Correct |
222 ms |
14104 KB |
Output is correct |
29 |
Correct |
193 ms |
14104 KB |
Output is correct |
30 |
Correct |
240 ms |
14104 KB |
Output is correct |
31 |
Correct |
384 ms |
18364 KB |
Output is correct |
32 |
Correct |
57 ms |
18364 KB |
Output is correct |
33 |
Correct |
65 ms |
18364 KB |
Output is correct |
34 |
Correct |
58 ms |
18364 KB |
Output is correct |
35 |
Correct |
78 ms |
18364 KB |
Output is correct |
36 |
Correct |
11 ms |
18364 KB |
Output is correct |
37 |
Correct |
78 ms |
18364 KB |
Output is correct |
38 |
Correct |
58 ms |
18364 KB |
Output is correct |
39 |
Correct |
114 ms |
18364 KB |
Output is correct |
40 |
Correct |
98 ms |
18364 KB |
Output is correct |
41 |
Correct |
182 ms |
18364 KB |
Output is correct |
42 |
Correct |
352 ms |
18364 KB |
Output is correct |
43 |
Correct |
163 ms |
18364 KB |
Output is correct |
44 |
Correct |
278 ms |
18364 KB |
Output is correct |
45 |
Correct |
289 ms |
18600 KB |
Output is correct |
46 |
Correct |
111 ms |
18600 KB |
Output is correct |
47 |
Correct |
151 ms |
18600 KB |
Output is correct |
48 |
Correct |
112 ms |
18600 KB |
Output is correct |
49 |
Correct |
189 ms |
18600 KB |
Output is correct |
50 |
Correct |
390 ms |
18600 KB |
Output is correct |
51 |
Correct |
235 ms |
18600 KB |
Output is correct |
52 |
Correct |
346 ms |
18600 KB |
Output is correct |
53 |
Correct |
275 ms |
18600 KB |
Output is correct |
54 |
Correct |
302 ms |
19096 KB |
Output is correct |
55 |
Correct |
191 ms |
19096 KB |
Output is correct |