#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
const char el = '\n';
const int maxn = 2e5+7;
struct Bitcoin {
vi arr;
int n;
void init(int sz) {
n = sz;
arr.assign(n+1, 0);
}
void upd(int i, int v) {
for (; i <= n; i+= i& -i) arr[i] = max(arr[i], v);
}
int get(int i) {
int res = 0;
for (; i > 0; i-= i& -i) res = max(res, arr[i]);
return res;
}
};
int n, cnt=1;
ll x;
ll a[maxn];
ll b[maxn];
ll c[maxn];
map<int, int> compress;
int pref[maxn], suf[maxn];
Bitcoin dp;
template<typename T>
void print(T a[], int n) { for (int i = 0; i < n; i++) cout << a[i] << ' '; cout << el; }
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
// freopen("test.inp", "r", stdin);
// freopen(".inp", "r", stdin);
// freopen(".out", "w", stdout);
cin >> n >> x;
for (int i = 1; i <= n; i++) cin>>a[i];
vll deck;
for (int i = 1; i <= n; i++) {
int pos = lower_bound(all(deck), a[i]) - deck.begin();
if (pos == deck.size()) deck.pb(a[i]);
else deck[pos] = a[i];
pref[i] = pos+1;
}
deck.clear();
for (int i = n; i >= 1; i--) {
int pos = lower_bound(all(deck), x - a[i]) - deck.begin();
suf[i] = pos+1;
int id = lower_bound(all(deck), -a[i]) - deck.begin();
if (id == deck.size()) deck.pb(-a[i]);
else deck[id] = -a[i];
}
int res = 0;
for (int i = 1; i <= n; i++) res = max(res, pref[i] + suf[i] - 1);
cout << res;
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... |