#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
set<pair<int, int>> s;
for (int i = n - 1; i >= 0; i--) {
pair<int, int> search = {a[i] + m + 1, 0};
auto it = s.lower_bound(search);
if (it == s.begin()) {
s.emplace(a[i], 1);
} else {
it = prev(it);
auto p = make_pair(a[i], it->second + 1);
while (!s.empty() && it->second <= p.second) {
it = s.erase(it);
}
s.insert(it, p);
}
}
pair<int, int> search{m + 1, 0};
auto it = s.lower_bound(search);
if (it == s.begin())
cout << n << endl;
else {
cout << n - prev(it)->second << endl;
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--)
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... |