#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define pb push_back
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n, m; cin >> n >> m;
vector<int> a(n+1);
for(int i=1; i<=n; i++) cin >> a[i];
reverse(all(a));
int dp[n+1] = {};
for(int i=0; i<=n; i++){
dp[i] = 1;
for(int j=0; j<i; j++){
if(a[j] <= a[i]+m){
dp[i] = max(dp[i], dp[j]+1);
}
}
}
int ans = (n+1) - dp[n];
cout << 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... |