#C4246. Longest Acceptable Increasing Subsequence
Longest Acceptable Increasing Subsequence
Longest Acceptable Increasing Subsequence
You are given an integer \(T\), representing the number of test cases. For each test case, you are provided with two integers \(n\) and \(k\), followed by an array of \(n\) integers. Your task is to determine the length of the longest contiguous subsequence where each adjacent pair \(a_i, a_{i+1}\) satisfies the conditions:
\(a_i < a_{i+1}\) and \(a_{i+1} - a_i \le k\).
In other words, find the maximum length of a segment in the array such that the sequence is strictly increasing and the difference between consecutive elements does not exceed \(k\). Output the result for each test case on a new line.
inputFormat
The input begins with an integer \(T\) denoting the number of test cases. Each test case is described in two lines:
- The first line contains two integers \(n\) and \(k\), where \(n\) is the number of elements in the array and \(k\) is the maximum allowed difference between consecutive elements.
- The second line contains \(n\) space-separated integers representing the array.
outputFormat
For each test case, output a single line with one integer: the length of the longest contiguous subsequence that satisfies the conditions \(a_i < a_{i+1}\) and \(a_{i+1} - a_i \le k\).
## sample1
6 3
1 3 6 9 12 15
6
</p>