PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#BS0000242. Dãy con biến thiên nhẹ (Smooth Subsequence)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Dãy con biến thiên nhẹ (Smooth Subsequence)

Smooth Subsequence

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

Given A1,…,ANA_1,\ldots,A_N and integer DD, select a subsequence by deleting any number of elements without rearranging the rest. Selected elements need not be contiguous in the original sequence. Maximize the length subject to an absolute difference of at most DD between consecutive selected elements. A singleton always qualifies.

Input

The first line contains integers N,DN,D. The second contains NN integers A1,…,ANA_1,\ldots,A_N.

Output

Print the maximum possible length as an integer.

Subtasks

  • Subtask 1 (20 points): 1≤N≤1501\le N\le 150; 0≤D≤5⋅1050\le D\le 5\cdot10^5; 1≤Ai≤5⋅1051\le A_i\le 5\cdot10^5 for every 1≤i≤N1\le i\le N.
  • Subtask 2 (30 points): 1≤N≤5⋅1051\le N\le 5\cdot10^5; D=0D=0; 1≤Ai≤5⋅1051\le A_i\le 5\cdot10^5 for every 1≤i≤N1\le i\le N.
  • Subtask 3 (50 points): 1≤N≤5⋅1051\le N\le 5\cdot10^5; 0≤D≤5⋅1050\le D\le 5\cdot10^5; 1≤Ai≤5⋅1051\le A_i\le 5\cdot10^5 for every 1≤i≤N1\le i\le N.

Examples

Input

5 2
2 4 9 3 5

Output

4

Explanation

Indices 1,2,4,5 give (2,4,3,5)(2,4,3,5) with differences 2,1,2. Length five would require selecting every element, including adjacent 4 and 9 whose difference is 5. Thus four is optimal.