K-th Maximum solution codechef
You are given a sequence of integersand an integer . Find the number of contiguous subsequences such that and the -th element of the subsequence ( ) is equal to the maximum of all elements of the entire sequence.
Input Format K-th Maximum solution codechef
- The first line of the input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first line of each test case contains two space-separated integers and .
- The second line contains space-separated integers .
For each test case, print a single line containing one integer — the number of contiguous subsequences satisfying the given conditions.
Constraints K-th Maximum solution codechef
- for each valid
- the sum of over all test cases does not exceed
Subtask #1 (10 points)
Subtask #2 (90 points) original constraints
Sample Input 1 K-th Maximum solution codechef
1 5 3 1 2 3 4 5
Sample Output 1
Explanation K-th Maximum solution codechef
Example case 1:is the only contiguous subsequence such that its -rd element is equal to the maximum of the whole sequence (which is ).