#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
int n, d;
int a[MAXN];
int ans = 1;
int pre[MAXN];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> d;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
}
vector<int> peal(n + 1, INT_MAX);
for (int i = 1; i <= n; i++)
{
int pos = lower_bound(peal.begin(), peal.end(), a[i]) - peal.begin();
peal[pos] = a[i];
pre[i] = pos + 1;
ans = max(ans, pre[i]);
}
for (int i = 0; i <= n; i++)
{
peal[i] = INT_MAX;
}
for (int i = n; i >= 1; i--)
{
int pos = lower_bound(peal.begin(), peal.end(), -a[i] + d) - peal.begin();
ans = max(ans, pre[i] + pos);
int cak = lower_bound(peal.begin(), peal.end(), -a[i]) - peal.begin();
peal[cak] = -a[i];
}
cout << ans;
}
| # | 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... |