#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin() , a.end()
#define FOR(i ,a , b) for(int i = a ; i <= b ; ++i)
#define bit(mask,i) ((mask>>i)&1)
#define name "task"
#define lo lower_bound
#define up upper_bound
#define count_bit1(x) __builtin_popcountll(x)
#define count_bit01(x) __builtin_clzll(x)
#define count_bit10(x) __builtin_ctzll(x)
using namespace std;
const int N=2e5+5;
long long a[N],n,k;
namespace sub23 {
const int N=5e3+5;
const long long INF=-1e18;
long long dp[N];
void solve() {
for(int i=1;i<=n;i++) cin >> a[i];
fill(dp,dp+N,INF);
long long ans=0;
for(int i=1;i<=n;i++) {
if(a[i]<=k*i) dp[i]=1;
for(int j=1;j<i;j++) {
if(dp[j] && a[i]-a[j]<=k*(i-j)) dp[i]=max(dp[i],dp[j]+1);
}
ans=max(ans,dp[i]);
}
cout << n-ans;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin >> n >> k;
sub23::solve();
// else sub_full::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... |