#include<bits/stdc++.h>
using namespace std;
int goleft[200100], goright[200100],vl[200100],pos[200100];
int main(){
cin.tie(0)->sync_with_stdio(0);
int n,x;
cin>>n>>x;
for(auto&i:pos)i=2e9;
pos[0]=0;
for(int i=1;i<=n;i++)
cin>>vl[i];
for(int i=n;i;i--){
goright[i]=lower_bound(pos,pos+n+1,1e9-vl[i])-pos;
pos[goright[i]] = 1e9-vl[i];
}
int ans=0;
for(auto&i:pos)i=2e9;
int A=clock();
pos[0]=0;
for(int i=1;i<=n;i++){
ans=max(ans,goright[i]+(int)(lower_bound(pos,pos+n+1,vl[i]+x-1)-pos)-1);
goleft[i]=lower_bound(pos,pos+n+1,vl[i])-pos;
pos[goleft[i]] = vl[i];
}
int B=clock();
// cerr<<(B-A )/ 1e6<<'\n';
cout<<ans<<'\n';
}
Compilation message
glo.cpp: In function 'int main()':
glo.cpp:18:9: warning: unused variable 'A' [-Wunused-variable]
18 | int A=clock();
| ^
glo.cpp:25:9: warning: unused variable 'B' [-Wunused-variable]
25 | int B=clock();
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Incorrect |
0 ms |
2652 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Incorrect |
0 ms |
2652 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Incorrect |
0 ms |
2652 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
3408 KB |
Output is correct |
2 |
Correct |
43 ms |
5468 KB |
Output is correct |
3 |
Correct |
45 ms |
5488 KB |
Output is correct |
4 |
Correct |
45 ms |
5488 KB |
Output is correct |
5 |
Correct |
29 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
2652 KB |
Output is correct |
2 |
Correct |
10 ms |
2692 KB |
Output is correct |
3 |
Correct |
10 ms |
2652 KB |
Output is correct |
4 |
Correct |
7 ms |
2648 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Incorrect |
9 ms |
2652 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
2908 KB |
Output is correct |
2 |
Correct |
19 ms |
3924 KB |
Output is correct |
3 |
Correct |
39 ms |
5476 KB |
Output is correct |
4 |
Correct |
31 ms |
4724 KB |
Output is correct |
5 |
Correct |
16 ms |
3420 KB |
Output is correct |
6 |
Correct |
26 ms |
4596 KB |
Output is correct |
7 |
Correct |
29 ms |
5200 KB |
Output is correct |
8 |
Correct |
16 ms |
3932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
1 ms |
2652 KB |
Output is correct |
7 |
Incorrect |
0 ms |
2652 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |