P24682 [AtCoder] Smooth Subsequence
普及
题目描述

Problem Statement

You are given $a sequence A = (A_1, A_2, \ldots, A_N)$ of length N.
Find the maximum length of a subsequence of A such that the absolute difference between any two adjacent terms is at most D.
A subsequence of a sequence A is a sequence that can be obtained by deleting zero or more elements from A and arranging the remaining elements in their original order.

Input

The input is given from Standard Input in the following format:
N D
$A_1 A_2 \ldots A_N$

Output

Print the answer.

Constraints

  • $1 \leq N \leq 5 \times 10^5$
  • $0 \leq D \leq 5 \times 10^5$
  • $1 \leq A_i \leq 5 \times 10^5$
  • All input values are integers.

Sample Input 1

4 2
3 5 1 2

Sample Output 1

3

The subsequence (3, 1, 2) of A has absolute differences of at most 2 between adjacent terms.

Sample Input 2

5 10
10 20 100 110 120

Sample Output 2

3

Sample Input 3

11 7
21 10 3 19 28 12 11 3 3 15 16

Sample Output 3

6

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
4 2 3 5 1 2
样例输出
3