// Starcraft 2 enjoyer + luv kd //
#include <bits/stdc++.h>
using namespace std;
#define LSOne(X) ((X) & -(X))
const int N = 2e5 + 5;
const int M = 4e5 + 5;
const int S = 640;
const int O = 2e5 + 5;
const int K = 15;
const int LG = 21;
const int P = 37;
const int INF = 1e9 + 5;
const int MOD = 998244353;
const int nx[] = {0, 1, 0, -1}, ny[] = {1, 0, -1, 0};
int n, v, a[N], pref[N], ans;
vector<int> len;
void solve()
{
cin >> n >> v;
ans = 0;
for (int x = 0; x < n; x++)
{
cin >> a[x];
}
for (int x = 0; x < n; x++)
{
auto it = lower_bound(len.begin(), len.end(), a[x]);
pref[x] = it - len.begin() + 1;
if (it == len.end())
{
len.push_back(a[x]);
}
else
{
len[it - len.begin()] = a[x];
}
}
ans = len.size();
len.clear();
for (int x = n - 1; x >= 0; x--)
{
auto it = lower_bound(len.begin(), len.end(), -(a[x] - v));
ans = max(ans, (int)(it - len.begin()) + pref[x]);
{
auto it = lower_bound(len.begin(), len.end(), -a[x]);
if (it == len.end())
{
len.push_back(-a[x]);
}
else
{
len[it - len.begin()] = -a[x];
}
}
}
cout << ans << "\n";
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
for (int x = 1; x <= t; x++)
{
solve();
}
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... |