//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
//#pragma GCC optimize("trapv")
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define mpr make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int nmax = 200011, mod = 1000000007, inf = 2000010000, key = 200003, lg = 20, block = 300;
const ll infll = 4000000000000000000;
const ld eps = 1e-9;
void solve()
{
int n;
cin >> n;
vector<int> pref(n);
vector<int> dp;
int x;
cin >> x;
vector<int> vc(n);
for(int i = 0; i < n; i++) {
cin >> vc[i];
int ind = lower_bound(all(dp), vc[i]) - dp.begin();
if(ind == dp.size())
dp.pb(vc[i]);
else
dp[ind] = vc[i];
pref[i] = ind + 1;
}
dp.clear();
int ans = 1;
for(int i = n - 1; i > 0; i--) {
int ind = lower_bound(all(dp), -vc[i]) - dp.begin();
if(ind == dp.size())
dp.pb(-vc[i]);
else
dp[ind] = -vc[i];
int t = lower_bound(all(dp), x - vc[i - 1]) - dp.begin();
ans = max(ans, pref[i - 1] + t);
}
cout << ans << "\n";
return ;
}
int main()
{
//freopen("cowjog.in","r",stdin);
//freopen("cowjog.out","w",stdout);
ios_base::sync_with_stdio(0);cin.tie(0);
srand(8713);
//init();
int t = 1;
//cin >> t;
//int t_ = t;
//t = rdi();
while(t--) {
//cout << "Case #" << t_ - t << ": ";
solve();
}
//flush();
return 0;
}
/*
8 11
7 3 5 12 2 7 3 4
*/
| # | 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... |