This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n,m;
cin>>n>>m;
int a[n+5];
a[0]=0;
for(int i=1;i<=n;i++){
cin>>a[i];
}
int dp[n+5];
fill(dp,dp+n+1,1e9);
dp[0]=0;//last remaining
int ans=n;
for(int i=1;i<=n;i++){
for(int j=0;j<i;j++){
if(a[j]+(i-j)*m>=a[i]){
dp[i]=min(dp[i],dp[j]+(i-j-1));
}
}
ans=min(ans,n-i+dp[i]);
}
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... |