#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
cin >> n >> x;
vector<int> a(n);
vector<int> lis, rlis;
vector<int> maxlis(n), rmaxlis(n);
vector<int> baselis(n), rbaselis(n);
for(int i = 0; i < n; i++){
cin >> a[i];
auto it = lower_bound(lis.begin(), lis.end(), a[i]);
auto it2 = lower_bound(lis.begin(), lis.end(), a[i] + x);
if(it == lis.end()){
lis.push_back(a[i]);
maxlis[i] = lis.size() - 1;
baselis[i] = lis.size() - 1;
}
else{
maxlis[i] = it2 - lis.begin();
baselis[i] = it - lis.begin();
*it = a[i];
}
}
for(int i = n - 1; i >= 0; i--){
auto it = lower_bound(rlis.begin(), rlis.end(), -a[i]);
auto it2 = lower_bound(rlis.begin(), rlis.end(), -a[i] - x);
if(it == rlis.end()){
rlis.push_back(-a[i]);
rmaxlis[i] = rlis.size() - 1;
rbaselis[i] = rlis.size() - 1;
}
else{
rmaxlis[i] = it2 - rlis.begin();
rbaselis[i] = it - rlis.begin();
*it = -a[i];
}
}
int maxi = 0;
for(int i = 0; i < n; i++){
maxi = max(maxi, max(maxlis[i] + rbaselis[i], baselis[i] + rmaxlis[i]));
}
cout << maxi + 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
504 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
400 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
2 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
4176 KB |
Output is correct |
2 |
Correct |
84 ms |
4176 KB |
Output is correct |
3 |
Correct |
77 ms |
4176 KB |
Output is correct |
4 |
Correct |
89 ms |
4364 KB |
Output is correct |
5 |
Correct |
49 ms |
5312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1416 KB |
Output is correct |
2 |
Correct |
21 ms |
1872 KB |
Output is correct |
3 |
Correct |
21 ms |
1872 KB |
Output is correct |
4 |
Correct |
13 ms |
1836 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
13 ms |
1988 KB |
Output is correct |
7 |
Correct |
19 ms |
1872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
47 ms |
2392 KB |
Output is correct |
2 |
Correct |
37 ms |
2400 KB |
Output is correct |
3 |
Correct |
74 ms |
4176 KB |
Output is correct |
4 |
Correct |
51 ms |
5316 KB |
Output is correct |
5 |
Correct |
24 ms |
2964 KB |
Output is correct |
6 |
Correct |
46 ms |
5168 KB |
Output is correct |
7 |
Correct |
63 ms |
5056 KB |
Output is correct |
8 |
Correct |
35 ms |
2384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
504 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
504 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
400 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
2 ms |
336 KB |
Output is correct |
27 |
Correct |
80 ms |
4176 KB |
Output is correct |
28 |
Correct |
84 ms |
4176 KB |
Output is correct |
29 |
Correct |
77 ms |
4176 KB |
Output is correct |
30 |
Correct |
89 ms |
4364 KB |
Output is correct |
31 |
Correct |
49 ms |
5312 KB |
Output is correct |
32 |
Correct |
19 ms |
1416 KB |
Output is correct |
33 |
Correct |
21 ms |
1872 KB |
Output is correct |
34 |
Correct |
21 ms |
1872 KB |
Output is correct |
35 |
Correct |
13 ms |
1836 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
13 ms |
1988 KB |
Output is correct |
38 |
Correct |
19 ms |
1872 KB |
Output is correct |
39 |
Correct |
47 ms |
2392 KB |
Output is correct |
40 |
Correct |
37 ms |
2400 KB |
Output is correct |
41 |
Correct |
74 ms |
4176 KB |
Output is correct |
42 |
Correct |
51 ms |
5316 KB |
Output is correct |
43 |
Correct |
24 ms |
2964 KB |
Output is correct |
44 |
Correct |
46 ms |
5168 KB |
Output is correct |
45 |
Correct |
63 ms |
5056 KB |
Output is correct |
46 |
Correct |
35 ms |
2384 KB |
Output is correct |
47 |
Correct |
38 ms |
3152 KB |
Output is correct |
48 |
Correct |
40 ms |
3152 KB |
Output is correct |
49 |
Correct |
79 ms |
6260 KB |
Output is correct |
50 |
Correct |
47 ms |
6608 KB |
Output is correct |
51 |
Correct |
42 ms |
5320 KB |
Output is correct |
52 |
Correct |
52 ms |
6592 KB |
Output is correct |
53 |
Correct |
49 ms |
6592 KB |
Output is correct |
54 |
Correct |
76 ms |
7360 KB |
Output is correct |
55 |
Correct |
72 ms |
6260 KB |
Output is correct |