#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...)
#endif
#define endl '\n'
#define int int64_t
const long long mod = 1000000007, MaxN = 200005 , INF = 1e18;
void solve(){
int N, M;
cin >> N >> M;
vector<int>a;
for(int i = 1;i <= N;i++){
int x;cin >> x;
if(M * i >= x)a.push_back(M * i - x);
}
if(a.empty()){
return void(cout << N << endl);
}
vector<int>dp = {a[0]};
for(int i = 1;i < a.size();i++){
if(a[i] >= dp.back()){
dp.push_back(a[i]);
}
else{
int pos = upper_bound(dp.begin(), dp.end(), a[i]) - dp.begin();
dp[pos] = a[i];
}
}
cout << N - dp.size() << endl;
}
signed main()
{
ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
FileRedirect("test");
#endif
// freopen("file.in","r",stdin);
// freopen("file.out","w",stdout);
int tc = 1;
// cin >> tc;
while (tc--)solve();
}
# | 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... |