#C7191. Longest Subsequence with Given Difference
Longest Subsequence with Given Difference
Longest Subsequence with Given Difference
You are given an array of integers and two numbers (n) and (k). Your task is to find the length of the longest subsequence in which the difference between consecutive elements is exactly (k). In other words, for a subsequence (a_1, a_2, \dots, a_m), it must hold for every (i) from 2 to (m) that (a_i - a_{i-1} = k). Note that the subsequence does not need to be contiguous; however, the order of the elements must remain as in the original array.
inputFormat
The input is read from standard input (stdin). The first line contains two integers (n) and (k), where (n) is the number of elements in the array and (k) is the required difference. The second line contains (n) space-separated integers representing the array.
outputFormat
Output a single integer on standard output (stdout) which is the length of the longest subsequence where the difference between consecutive elements is exactly (k).## sample
5 2
1 3 5 7 9
5
</p>