#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define ll long long
#define int long long
#define all(x) x.begin(), x.end()
#define seea(x) for(int i = 0; i < x; i++)
#define vc vector
using namespace std;
const int INF = LLONG_MAX;
void solve(){
int n, x;
cin >> n >> x;
vc<int> a(n), dp(n, INF), L(n), R(n);
seea(n) cin >> a[i];
for(int i = 0; i < n; i++){
int j = lower_bound(all(dp), a[i]) - dp.begin();
dp[j] = a[i];
L[i] = j + 1;
}
fill(all(dp), INF);
for(int i = n - 1; i >= 0; i--){
int j = lower_bound(all(dp), -a[i] + x) - dp.begin();
R[i] = j + 1;
int k = lower_bound(all(dp), -a[i]) - dp.begin();
dp[k] = -a[i];
}
int ans = 0;
for(int i = 0; i < n; i++){
ans = max(ans, L[i] + R[i] - 1);
}
cout << ans << endl;
}
signed main(){
fast;
solve();
}
# | 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... |