#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAXN = 5e5 + 10;
int a[MAXN];
int pl[MAXN];
int main()
{
int n, x, ans = 0;
cin >> n >> x;
for (int i = 1; i <= n; i++)
cin >> a[i];
vector <int> dp (n, INT_MAX);
vector <int> pd (n, INT_MAX);
for (int i = 1; i <= n; i++)
{
int it = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin();
dp[it] = a[i];
pl[i] = it + 1;
ans = max(ans, pl[i]);
}
for (int i = n; i >= 1; i--)
{
int it = lower_bound(pd.begin(), pd.end(), x - a[i]) - pd.begin();
ans = max(ans, pl[i] + it);
it = lower_bound(pd.begin(), pd.end(), -a[i]) - pd.begin();
pd[it] = -a[i];
}
cout << ans << endl;
}
# | 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... |