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 s second
#define pb push_back
#define f first
using namespace std;
const int N = 200005;
int a[N],l[N],r[N];
vector <int> vec;
signed main() {
int n,x;
cin>>n>>x;
for (int i = 1; i <= n; i++)
vec.pb(1e9);
for (int i = 1; i <= n; i++){
cin>>a[i];
int id = lower_bound(vec.begin(),vec.end(), a[i]) - vec.begin();
vec[id] = a[i];
l[i] = id + 1;
}
vec.clear();
for (int i = 1; i <= n; i++)
vec.pb(1e9);
for (int i = n; i >= 1; i--){
int val = -(a[i] - x);
int id = lower_bound(vec.begin(),vec.end(), val) - vec.begin();
r[i] = id + 1;
id = lower_bound(vec.begin(),vec.end(), -a[i]) - vec.begin();
vec[id] = -a[i];
}
int ans=0;
for (int i = 1; i <= n; i++)
ans=max(ans,l[i] + r[i] - 1);
cout<<ans<<"\n";
}
# | 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... |