This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |