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 int long long
int val[200010];
int highest[200010];
int sz[200010];
int lis[200010];
int32_t main(){
cin.tie(nullptr)->sync_with_stdio(false);
int n,x;
cin >> n >> x;
for(int i= 0;i<n;i++){
cin >> val[i];
}
int size= 0;
int ans = 0;
for(int i = 0;i<n;i++){
int idx = lower_bound(lis,lis+size,val[i])-lis;
if(idx==size)size++;
lis[idx] = val[i];
highest[i] = lis[size-1];
sz[i] = size;
}
ans = size;
memset(lis,0,sizeof(lis));
size = 0;
for(int i = n-1;i>=1;i--){
int idx = lower_bound(lis,lis+size,-(val[i]+x))-lis;
if(idx==size)size++;
lis[idx] = -(val[i]+x);
int id = lower_bound(lis,lis+size,-highest[i-1])-lis;
ans = max(ans,id+sz[i-1]);
}
ans = max(ans,size);
cout << ans;
}
# | 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... |