import java.io.*;
import java.util.*;
public class triusis {
public static int MIN = (-1)*((int) 2E9);
public static void main(String[] args) throws IOException {
BufferedReader scan = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer l1 = new StringTokenizer(scan.readLine()); int num = Integer.parseInt(l1.nextToken()); int jump = Integer.parseInt(l1.nextToken());
int[] arr = new int[num];
for (int i = 0;i<num;i++) {
StringTokenizer st = new StringTokenizer(scan.readLine());
arr[i] = Integer.parseInt(st.nextToken());
}
int[] dp = new int[num+1];
Arrays.fill(dp, MIN); dp[0] = arr[0];
for (int i = 1;i<num;i++) {
for (int j = i;j>=1;j--) {
if (dp[j]>=arr[i]-jump) {
dp[j] = arr[i];
dp[j] = Math.max(dp[j], dp[j-1]+jump);
} else {
if (dp[j-1]==-1) dp[j] = MIN;
else dp[j] = dp[j-1]+jump;
}
}
if (dp[0]>=arr[i]-jump) dp[0] = arr[i];
else dp[0] = MIN;
}
int ans = num;
for (int i = num;i>=0;i--) {
if (dp[i]>=0) ans = i;
}
System.out.println(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... |