import java.io.*;
import java.util.*;
public class triusis {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int m = Integer.parseInt(st.nextToken());
int[] h = new int[n];
for (int i=0; i<n; i++) h[i] = Integer.parseInt(br.readLine());
int res = solve(h, m);
pw.println(res);
pw.close();
br.close();
}
private static int solve(int[] h, int m) {
int n = h.length;
int[] dp = new int[n];
dp[0] = (h[0]<=m)?1:0;
for (int i=1; i<n; i++) {
dp[i] = (h[i]<=m*(i+1))?1:0;
for (int j=i-1; j>=0; j--) {
if (m*(i-j)<h[i]-h[j]&&h[i]>h[j]) break;
if (h[i]<=h[j]+m*(i-j)&&dp[j]>0) {
dp[i] = Math.max(dp[i], dp[j]+1);
if (dp[i]==dp[j]+1&&dp[j]==i-j) break;
}
}
}
int mxv = 0;
for (int i=0; i<n; i++) mxv = Math.max(mxv, dp[i]);
return n-mxv;
}
}
# | 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... |