#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int NMAX = 2e5;
const ll INF = 1e18;
int n, m, answer;
ll a[NMAX + 1];
ll dp[NMAX + 1];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++) {
int x;
cin >> x;
a[i] = (ll) m * i - x;
}
for(int i = 1; i <= n; i++) {
dp[i] = INF;
}
dp[0] = -INF;
for(int i = 1; i <= n; i++) {
if(a[i] >= 0) {
int l = upper_bound(dp, dp + n + 1, a[i]) - dp;
dp[l] = a[i];
answer = max(answer, l);
}
}
cout << n - answer << '\n';
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... |