This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* Dirty code by Articulation_points */
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int oo=2e18+1;
const int MAXN=2e5;
int n,k,a[MAXN+5],dp[MAXN+5],ans;
vector<int>v;
signed main(){
cin.tie(0)->sync_with_stdio(false);
cout.tie(0);
cin>>n>>k;
for(int i=1;i<=n;++i)
cin>>a[i];
v.push_back(oo);
for(int i=1;i<=n;++i)
v.push_back(-oo);
for(int i=n;i>=1;--i){
int x=lower_bound(v.begin(),v.end(),a[i],greater<int>())-v.begin();
ans=max(ans,x);
dp[i]=x;
v[x]=a[i];
}
v.clear();
v.push_back(-oo);
for(int i=1;i<=n;++i)
v.push_back(oo);
for(int i=1;i<=n;++i){
int x=lower_bound(v.begin(),v.end(),a[i]+k)-v.begin();
ans=max(ans,x+dp[i]-1);
x=lower_bound(v.begin(),v.end(),a[i])-v.begin();
v[x]=a[i];
}
cout<<ans<<'\n';
}
# | 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... |