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 ll long long
#define all(v) (v).begin(),(v).end()
using namespace std;
ll i,j,n,x,a[200005],b[200005],ans;
vector<ll> v;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> x;
for(i=1;i<=n;i++){
cin >> a[i];
j=lower_bound(all(v),a[i]+x)-v.begin();
b[i]=j+1;
j=lower_bound(all(v),a[i])-v.begin();
if(j==v.size()) v.push_back(a[i]);
else v[j]=a[i];
}
v.clear();
for(i=n;i>=1;i--){
j=lower_bound(all(v),-a[i])-v.begin();
ans=max(ans,b[i]+j);
if(j==v.size()) v.push_back(-a[i]);
else v[j]=-a[i];
}
cout << ans;
}
Compilation message (stderr)
glo.cpp: In function 'int main()':
glo.cpp:17:7: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | if(j==v.size()) v.push_back(a[i]);
| ~^~~~~~~~~~
glo.cpp:24:7: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | if(j==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... |