#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, x;
cin >> n >> x;
vector<int> temps(n);
for (int i = 0; i < n; ++i) cin >> temps[i];
int longest = 0;
vector<int> dp(n, INT_MAX);
vector<int> pref_longest(n);
for (int i = 0; i < n; ++i){
int pos = lower_bound(dp.begin(), dp.end(), temps[i]) - dp.begin();
dp[pos] = temps[i];
pref_longest[i] = pos + 1;
longest = max(longest, pref_longest[i]);
}
dp = vector<int> (n, INT_MAX);
for (int i = n - 1; i >= 0; --i){
int pos = lower_bound(dp.begin(), dp.end(), -temps[i] + x) - dp.begin();
longest = max(longest, pref_longest[i] + pos);
pos = lower_bound(dp.begin(), dp.end(), -temps[i]) - dp.begin();
dp[pos] = -temps[i];
}
cout << longest;
return 0;
}
# | 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... |