#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll, ll>
#define fi first
#define sec second
#define ld long double
const ll N = 1e5;
const ll INF = 4e18;
const ll MOD = 1e9 + 7;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int tc = 1;
// cin >> tc;
for(;tc--;){
ll n, x; cin >> n >> x;
vector<ll> a(n + 5);
for(int i = 1; i <= n; i++) cin >> a[i];
vector<ll> ps(n + 5);
vector<ll> dp(n + 5, INF);
ll ans = 0;
for(int i = 1; i <= n; i++){
ll pt = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin();
ps[i] = pt + 1;
ans = max(ans, pt + 1);
dp[pt] = a[i];
}
for(int i = 0; i <= n; i++) dp[i] = INF;
for(int i = n; i >= 1; --i){
ll pt = lower_bound(dp.begin(), dp.end(), -(a[i] - x)) - dp.begin();
ans = max(ans, ps[i] + pt);
pt = lower_bound(dp.begin(), dp.end(), -a[i]) - dp.begin();
dp[pt] = -a[i];
}
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... |