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;
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fs first
#define sc second
#define pb push_back
vector<int> lis(vector<int> a){
int n=a.size();
vector<int> ans(n),v;
for(int i=0;i<n;i++){
if(v.empty()||v.back()<a[i])v.pb(a[i]);
else{
int idx=lower_bound(v.begin(),v.end(),a[i])-v.begin();
v[idx]=a[i];
}
ans[i]=v.size();
}
return ans;
}
void solve() {
int n,x;
cin>>n>>x;
vector<int> a(n);
for(int i=0;i<n;i++)cin>>a[i];
vector<int> v1=lis(a),v2(n),a2(n);
for(int i=0;i<n;i++)a2[i]=-a[n-1-i];
vector<int> t=lis(a2);
for(int i=0;i<n;i++)v2[i]=t[n-1-i];
int ans=1;
for(int i=0;i<n;i++){
for(int j=i+1;j<n;j++)if(a[i]-x<a[j]){
ans=max(ans,v1[i]+v2[j]);
}
}
cout<<ans;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
solve();
}
# | 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... |