#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair <int, int>
#define ill pair <ll, ll>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define file "test"
using namespace std;
const int N = 2e5 + 2;
const ll MOD = 998244353;
const ll INF = 1e18;
const int base = 311;
const int BLOCK_SIZE = 2000;
int n, h;
int a[N], bit[N];
vector <int> b;
void upd(int idx, int v) {
for (; idx <= n; idx += idx & -idx)
bit[idx] = max(bit[idx], v);
}
int get(int idx) {
int ans = 0;
for (; idx > 0; idx -= idx & -idx)
ans = max(ans, bit[idx]);
return ans;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n >> h;
for (int i = 1; i <= n; i ++) {
cin >> a[i], a[i] -= h * i;
b.push_back(a[i]);
}
sort(all(b));
b.erase(unique(all(b)), b.end());
for (int i = 1; i <= n; i ++)
a[i] = lower_bound(all(b), a[i]) - b.begin() + 1;
int ans = 0;
for (int i = n; i > 0; i --) {
int res = get(a[i]) + 1;
ans = max(ans, res);
upd(a[i], res);
}
cout << n - ans;
}
/*
/\_/\ zzZ
(= -_-)
/ >u >u
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |