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>
#define int long long
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
int n,x;
cin>>n>>x;
vector <int> a(n);
for(int i=0;i<n;i++)cin>>a[i];
vector <int> v(n+1,1e18),v2(n+1,1e18);
vector <int> l(n+1),r(n+1);
v[0]=-1e18;
v2[0]=-1e18;
for(int i=0;i<n;i++){
auto pos=lower_bound(all(v),a[i])-v.begin();
l[i]=pos;
v[pos]=a[i];
}
for(int i=n-1;i>=0;i--){
auto pos=lower_bound(all(v2),-(a[i]-x))-v2.begin();
r[i]=pos;
pos=lower_bound(all(v2),-a[i])-v2.begin();
v2[pos]=-a[i];
}
int mx=0;
for(int i=0;i<n;i++){
mx=max(mx,l[i]+r[i]-1);
}
cout<<mx<<"\n";
}
/*
8 10
7 3 5 12 2 7 3 4
*/
# | 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... |