Longest Increasing Subsequence

2.7

13 votes
Medium
Problem

Shashank loves longest increasing subsequence. A subsequence, 1 ≤ i1 < i2 < ... < ik ≤ n is called increasing if A[i1]  ≤ A[i2]  ≤ A[i3]  ≤ ...  ≤ A[ik]. An increasing subsequence is called longest if it has maximum length among all increasing subsequences.

Shashank added one more restriction that the chosen indexes atleast differ by D. i.e. ij - ij-1D for all j ≥ 1.

Help Shashank by finding length of LIS after the added restriction.

Input Format

First line contains two space separated integers n and D
Second line contains n space separating integers which are the elements of array A as defined above.

Output Format

Output a single integer, which is answer to the problem

Constraints

  • 1 ≤ n, A[i] ≤ 100000
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

LIS which satisfies the above restrictions is {1, 3, 5}

Editor Image

?