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;
const long long MAX=2*1e5+10;
long long pr[MAX];
long long niza[MAX];
int main()
{
long long n,x;
cin>>n>>x;
for(long long i=0; i<n; i++)cin>>niza[i];
vector<long long> help(n);
for(long long i=0; i<n; i++)help[i]=INT_MAX;
long long res=0;
for(long long i=0; i<n; i++)
{
long long nw=lower_bound(help.begin(),help.end(),niza[i])-help.begin();
help[nw]=niza[i];
pr[i]=nw+1;
res=max(res,pr[i]);
}
for(long long i=0; i<n; i++)help[i]=INT_MAX;
for (long long i=n-1; i>=0; i--) {
long long nw=lower_bound(help.begin(),help.end(),-niza[i]+x)-help.begin();
res=max(res,pr[i]+nw);
long long tmp=lower_bound(help.begin(),help.end(),-niza[i])-help.begin();
help[tmp]=-niza[i];
}
cout<<res<<endl;
return 0;
}
# | 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... |