#K76557. Count Valid Subarrays
Count Valid Subarrays
Count Valid Subarrays
You are given an array A of N integers, and three integers N, M, and X. Your task is to determine the number of contiguous subarrays of length M for which the sum of the maximum and minimum elements is greater than X.
Formally, for each contiguous subarray S = [a_i, a_{i+1}, \ldots, a_{i+M-1}], you must check whether:
\( \max(S) + \min(S) > X \)
If the above condition is satisfied, the subarray is considered valid. Compute the total number of valid subarrays for each test case.
inputFormat
The first line of input contains an integer T denoting the number of test cases.
For each test case, the first line contains three space-separated integers: N (length of the array), M (length of subarray), and X (the threshold value).
The second line contains N space-separated integers representing the array A.
outputFormat
For each test case, output a single integer on a new line denoting the number of contiguous subarrays of length M such that the sum of the maximum and minimum elements is greater than X.
## sample3
5 3 10
1 3 8 6 4
4 2 7
9 7 3 8
5 2 6
2 1 4 5 3
2
3
2
</p>