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

#CC0000065. Dãy con tăng với giới hạn bước nhảy (Longest Increasing Subsequence II)

HỌC THEO LỘ TRÌNH

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

2 lộ trình

Dãy con tăng với giới hạn bước nhảy (Longest Increasing Subsequence II)

Longest Increasing Subsequence II

Source: LeetCode

Version: Phuoc Hung OJ Extended

Problem Statement

Given an integer array a1,…,ana_1,\ldots,a_n and a positive integer kk, find the longest subsequence whose consecutive elements strictly increase and differ by at most kk. The original order must be preserved.

Input

The first line contains n,kn,k. The second line contains the array aia_i. This is the stdin/stdout adaptation of the original LeetCode function problem.

Output

Print the maximum length of a valid subsequence.

Subtasks

Original constraints: 1≤n≤1051\le n\le10^5; 1≤ai,k≤1051\le a_i,k\le10^5.

  • Subtask 1 (20 points): 1≤n≤181\le n\le18; 1≤k,ai≤251\le k,a_i\le25.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le2000; 1≤k,ai≤20001\le k,a_i\le2000.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le100000; 1≤k,ai≤1000001\le k,a_i\le100000.

Examples

Input

9 3
4 2 1 4 3 4 5 8 15

Output

5

Explanation

For instance, 1,3,4,5,81,3,4,5,8 is valid: successive differences are 2,1,1,32,1,1,3, all at most 33. The answer is 55.