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 maxN 200005
using namespace std;
int a[maxN],d[maxN],n,x,i;
void LDS(){
vector <int> v;
for(int i=0;i<n;i++) v.push_back(0);
for(int i=n-1;i>=0;i--){
int tmp=upper_bound(v.begin(),v.end(),a[i])-v.begin()-1;
v[tmp]=a[i];
d[i]=n-tmp;
//cout<<i<<" "<<d[i]<<endl;
}
}
int LIS(){
vector <int> v;
int ans=0;
for(int i=0;i<n;i++){
int tmp=lower_bound(v.begin(),v.end(),a[i])-v.begin();
int p;
p=lower_bound(v.begin(),v.end(),a[i]+x)-v.begin();
//cout<<p<<" "<<d[i]<<endl;
ans=max(ans,p+d[i]);
if(tmp==v.size()) v.push_back(a[i]);
else v[tmp]=a[i];
}
return ans;
}
int main() {
cin>>n>>x;
for(i=0;i<n;i++) cin>>a[i];
LDS();
cout<<LIS()<<endl;
return 0;
}
Compilation message (stderr)
glo.cpp: In function 'int LIS()':
glo.cpp:27:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(tmp==v.size()) v.push_back(a[i]);
~~~^~~~~~~~~~
# | 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... |