#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
const int N=5005;
int dp[N];
int tmp[N];
int a[N];
signed main(){
for(int i=0;i<N;i++){
dp[i]=1e9;
tmp[i]=1e9;
}
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++)cin>>a[i];
tmp[0]=0;
int ans=n;
for(int i=1;i<=n;i++){
for(int hi=0;hi<=1000;hi++){
for(int hj=0;hj<=1000;hj++){
if(hi-hj>k)continue;
if(hi!=a[i]){
dp[hi]=min(dp[hi],tmp[hj]+1);
if(i==n)ans=min(ans,dp[hi]);
}
else{
dp[hi]=min(dp[hi],tmp[hj]);
if(i==n)ans=min(ans,dp[hi]);
}
}
}
for(int j=0;j<=1000;j++){
tmp[j]=dp[j];
dp[j]=1e9;
}
}
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... |