#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main() {_
int n,x;
cin>>n>>x;
vector<int> num(n);
for(auto &u:num){
cin>>u;
}
int l[n],r[n];
int ans=0;
vector<int> lis;
for(int i=0;i<n;i++){
int pos=lower_bound(lis.begin(),lis.end(),num[i])-lis.begin();
l[i]=pos+1;
pos=lower_bound(lis.begin(),lis.end(),num[i]-x)-lis.begin();
if(pos==lis.size()){
lis.push_back(num[i]-x);
}
else{
lis[pos]=num[i]-x;
}
}
lis.clear();
for(int i=n-1;i>=0;i--){
int pos=lower_bound(lis.begin(),lis.end(),num[i],greater<int>())-lis.begin();
if(pos==lis.size()){
lis.push_back(num[i]);
r[i]=lis.size();
}
else{
lis[pos]=num[i];
r[i]=pos+1;
}
}
for(int i=0;i<n;i++){
//cout<<l[i]<<' '<<r[i]<<'\n';
ans=max(ans,l[i]+r[i]-1);
}
cout<<ans;
return 0;
}
//maybe its multiset not set
Compilation message
glo.cpp: In function 'int main()':
glo.cpp:22:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | if(pos==lis.size()){
| ~~~^~~~~~~~~~~~
glo.cpp:32:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | if(pos==lis.size()){
| ~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
320 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 |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 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 |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
320 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 |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
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 |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
320 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 |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
324 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
328 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 |
52 ms |
2664 KB |
Output is correct |
2 |
Correct |
52 ms |
2756 KB |
Output is correct |
3 |
Correct |
61 ms |
2760 KB |
Output is correct |
4 |
Correct |
48 ms |
2760 KB |
Output is correct |
5 |
Correct |
31 ms |
3340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
908 KB |
Output is correct |
2 |
Correct |
14 ms |
1364 KB |
Output is correct |
3 |
Correct |
17 ms |
1364 KB |
Output is correct |
4 |
Correct |
8 ms |
1300 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
9 ms |
1356 KB |
Output is correct |
7 |
Correct |
11 ms |
1400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
1492 KB |
Output is correct |
2 |
Correct |
24 ms |
2364 KB |
Output is correct |
3 |
Correct |
59 ms |
4548 KB |
Output is correct |
4 |
Correct |
32 ms |
4412 KB |
Output is correct |
5 |
Correct |
16 ms |
2384 KB |
Output is correct |
6 |
Correct |
30 ms |
4384 KB |
Output is correct |
7 |
Correct |
33 ms |
5012 KB |
Output is correct |
8 |
Correct |
24 ms |
2384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
320 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 |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
324 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
2 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
324 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
328 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
52 ms |
2664 KB |
Output is correct |
28 |
Correct |
52 ms |
2756 KB |
Output is correct |
29 |
Correct |
61 ms |
2760 KB |
Output is correct |
30 |
Correct |
48 ms |
2760 KB |
Output is correct |
31 |
Correct |
31 ms |
3340 KB |
Output is correct |
32 |
Correct |
12 ms |
908 KB |
Output is correct |
33 |
Correct |
14 ms |
1364 KB |
Output is correct |
34 |
Correct |
17 ms |
1364 KB |
Output is correct |
35 |
Correct |
8 ms |
1300 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
9 ms |
1356 KB |
Output is correct |
38 |
Correct |
11 ms |
1400 KB |
Output is correct |
39 |
Correct |
23 ms |
1492 KB |
Output is correct |
40 |
Correct |
24 ms |
2364 KB |
Output is correct |
41 |
Correct |
59 ms |
4548 KB |
Output is correct |
42 |
Correct |
32 ms |
4412 KB |
Output is correct |
43 |
Correct |
16 ms |
2384 KB |
Output is correct |
44 |
Correct |
30 ms |
4384 KB |
Output is correct |
45 |
Correct |
33 ms |
5012 KB |
Output is correct |
46 |
Correct |
24 ms |
2384 KB |
Output is correct |
47 |
Correct |
34 ms |
2364 KB |
Output is correct |
48 |
Correct |
27 ms |
2448 KB |
Output is correct |
49 |
Correct |
70 ms |
3808 KB |
Output is correct |
50 |
Correct |
39 ms |
4416 KB |
Output is correct |
51 |
Correct |
30 ms |
3512 KB |
Output is correct |
52 |
Correct |
32 ms |
4432 KB |
Output is correct |
53 |
Correct |
28 ms |
4448 KB |
Output is correct |
54 |
Correct |
33 ms |
4376 KB |
Output is correct |
55 |
Correct |
51 ms |
3796 KB |
Output is correct |