#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define FOD(i, a, b) for(int i = (a); i >= (b); i--)
#define file(name) if(fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
#define el cout << '\n'
#define maxn int(2e5 + 5)
using namespace std;
typedef long long ll;
int n, k, a[maxn], id[maxn], t[maxn];
vector<ll> vals;
void update(int x, int v) {
for(; x; x -= x & -x) t[x] = max(t[x], v);
}
int get(int x) {
int res = 0;
for(; x <= n; x += x & -x) res = max(res, t[x]);
return res;
}
void compress() {
FOR(i, 1, n) if(a[i] - 1LL * k * i < 0) vals.push_back(a[i] - 1LL * k * i);
sort(vals.begin(), vals.end());
vals.resize(unique(vals.begin(), vals.end()) - vals.begin());
FOR(i, 1, n) if(a[i] - 1LL * k * i < 0) id[i] = lower_bound(vals.begin(), vals.end(), a[i] - 1LL * k * i) - vals.begin() + 1;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> k;
FOR(i, 1, n) cin >> a[i];
compress();
FOR(i, 1, n) if(a[i] - 1LL * k * i < 0) {
int x = get(id[i]);
if(x == 0) x = (a[i] <= k);
else x++;
update(id[i], x);
}
cout << n - get(1);
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... |