#include <bits/stdc++.h>
#define ll long long
#define s second
#define pb push_back
#define f first
using namespace std;
const int N = 200005;
int a[N],l[N],r[N];
vector <int> vec;
signed main() {
int n,x;
cin>>n>>x;
for (int i = 1; i <= n; i++)
vec.pb(1e9);
for (int i = 1; i <= n; i++){
cin>>a[i];
int id = lower_bound(vec.begin(),vec.end(), a[i]) - vec.begin();
vec[id] = a[i];
l[i] = id + 1;
}
vec.clear();
for (int i = 1; i <= n; i++)
vec.pb(1e9);
for (int i = n; i >= 1; i--){
int val = -(a[i] - x);
int id = lower_bound(vec.begin(),vec.end(), val) - vec.begin();
r[i] = id + 1;
id = lower_bound(vec.begin(),vec.end(), -a[i]) - vec.begin();
vec[id] = -a[i];
}
int ans=0;
for (int i = 1; i <= n; i++)
ans=max(ans,l[i] + r[i] - 1);
cout<<ans<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 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 |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 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 |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
304 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
304 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 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 |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
304 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
304 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
308 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
316 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 |
312 KB |
Output is correct |
25 |
Correct |
1 ms |
308 KB |
Output is correct |
26 |
Correct |
1 ms |
304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
119 ms |
5436 KB |
Output is correct |
2 |
Correct |
121 ms |
5364 KB |
Output is correct |
3 |
Correct |
129 ms |
5440 KB |
Output is correct |
4 |
Correct |
124 ms |
5448 KB |
Output is correct |
5 |
Correct |
90 ms |
4688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
1592 KB |
Output is correct |
2 |
Correct |
37 ms |
1592 KB |
Output is correct |
3 |
Correct |
33 ms |
1664 KB |
Output is correct |
4 |
Correct |
28 ms |
1448 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
23 ms |
1496 KB |
Output is correct |
7 |
Correct |
25 ms |
1616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
65 ms |
2852 KB |
Output is correct |
2 |
Correct |
70 ms |
2900 KB |
Output is correct |
3 |
Correct |
136 ms |
5472 KB |
Output is correct |
4 |
Correct |
119 ms |
4620 KB |
Output is correct |
5 |
Correct |
45 ms |
2464 KB |
Output is correct |
6 |
Correct |
78 ms |
4480 KB |
Output is correct |
7 |
Correct |
104 ms |
5364 KB |
Output is correct |
8 |
Correct |
54 ms |
2884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 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 |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
304 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
304 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
308 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
316 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 |
312 KB |
Output is correct |
25 |
Correct |
1 ms |
308 KB |
Output is correct |
26 |
Correct |
1 ms |
304 KB |
Output is correct |
27 |
Correct |
119 ms |
5436 KB |
Output is correct |
28 |
Correct |
121 ms |
5364 KB |
Output is correct |
29 |
Correct |
129 ms |
5440 KB |
Output is correct |
30 |
Correct |
124 ms |
5448 KB |
Output is correct |
31 |
Correct |
90 ms |
4688 KB |
Output is correct |
32 |
Correct |
32 ms |
1592 KB |
Output is correct |
33 |
Correct |
37 ms |
1592 KB |
Output is correct |
34 |
Correct |
33 ms |
1664 KB |
Output is correct |
35 |
Correct |
28 ms |
1448 KB |
Output is correct |
36 |
Correct |
0 ms |
212 KB |
Output is correct |
37 |
Correct |
23 ms |
1496 KB |
Output is correct |
38 |
Correct |
25 ms |
1616 KB |
Output is correct |
39 |
Correct |
65 ms |
2852 KB |
Output is correct |
40 |
Correct |
70 ms |
2900 KB |
Output is correct |
41 |
Correct |
136 ms |
5472 KB |
Output is correct |
42 |
Correct |
119 ms |
4620 KB |
Output is correct |
43 |
Correct |
45 ms |
2464 KB |
Output is correct |
44 |
Correct |
78 ms |
4480 KB |
Output is correct |
45 |
Correct |
104 ms |
5364 KB |
Output is correct |
46 |
Correct |
54 ms |
2884 KB |
Output is correct |
47 |
Correct |
57 ms |
2884 KB |
Output is correct |
48 |
Correct |
60 ms |
2924 KB |
Output is correct |
49 |
Correct |
120 ms |
5408 KB |
Output is correct |
50 |
Correct |
86 ms |
4700 KB |
Output is correct |
51 |
Correct |
57 ms |
3616 KB |
Output is correct |
52 |
Correct |
77 ms |
4764 KB |
Output is correct |
53 |
Correct |
85 ms |
4788 KB |
Output is correct |
54 |
Correct |
114 ms |
5436 KB |
Output is correct |
55 |
Correct |
128 ms |
5404 KB |
Output is correct |