#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define int long long
int32_t main() {
int n, m;
cin >> n >> m;
int poles[n+1];
poles[0] = 0;
for (int i=1; i<=n; i++) {
cin >> poles[i];
poles[i] -= i*m;
}
vector<int> ldsn(n+1), endwithlen(n+1, -9223372036854775807);
endwithlen[0] = 0;
int ans = 0;
for (int i=1; i<=n; i++) {
int firstbad = upper_bound(endwithlen.begin(), endwithlen.end(), poles[i], greater<int>()) - endwithlen.begin();
ldsn[i] = firstbad;
if (firstbad == 0) continue;
endwithlen[firstbad] = max(endwithlen[firstbad], poles[i]);
ans = max(ans, firstbad);
}
cout << n-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... |