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[] heights = new int[n];
st = new StringTokenizer(br.readLine());
for (int i=0; i<n; i++) heights[i] = Integer.parseInt(st.nextToken());
int result = solve(heights, m);
pw.println(result);
pw.close();
br.close();
}
private static int solve(int[] heights, int m) {
int n = heights.length, currh = 0, c = 0;
if (n==0) return 0;
boolean[] modded = new boolean[n];
for (int i=0; i<n; i++) {
if (heights[i]>currh+m) {
modded[i] = true;
currh = currh+m;
} else currh = heights[i];
}
for (boolean x:modded) if (x) c++;
return c;
}
}
# | 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... |