#C5481. Longest Contiguous Subsequence Within K
Longest Contiguous Subsequence Within K
Longest Contiguous Subsequence Within K
You are given an array of integers representing scores and an integer (K). Your task is to find the length of the longest contiguous subsequence such that the difference between the maximum and minimum elements in the subsequence is less than or equal to (K), i.e. (\max - \min \le K). The subsequence must be contiguous (i.e. a continuous segment of the array).
For example, given the scores [5, 3, 8, 6, 7, 4, 2] and (K = 4), the longest subsequence that satisfies the condition is of length 4. If no valid subsequence longer than one element exists, the answer is 1 (unless the array is empty, in which case the answer is 0).
inputFormat
The first line contains two integers (n) and (K), where (n) is the number of scores. The second line contains (n) space-separated integers representing the scores. If (n = 0), the second line will be empty.
outputFormat
Output a single integer denoting the length of the longest contiguous subsequence which satisfies (\max - \min \le K).## sample
7 4
5 3 8 6 7 4 2
4