An integer v is a median of an array b of length m if and only if: v is greater than or…
- User
An integer v is a median of an array b of length m if and only if:
v is greater than or equal to at least ⌈m2⌉ elements of the array, and v is less than or equal to at least ⌈m2⌉ elements of the array. For instance: the only median of [9,3,7] is 7 , the medians of [5,3,7,9] are 5 , 6 , and 7 , and the only median of [2,2,2] is 2 . You're given an integer k and an array a1,…,an of integers between 1 and n .
An integer v from 1 to n is said to be a submedian if there exists at least one pair of indices (l,r) such that
1≤l≤r≤n , r−l+1≥k , v is a median of the subarray [al,…,ar] . It can be proven that there always exists at least one submedian. Find the maximum submedian vmax and any corresponding pair of indices (l,r) .
Input Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤50000 ). The description of the test cases follows.
The first line of each test case contains two integers n and k (1≤k≤n≤300000 ).
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤n ).
It is guaranteed that the sum of n over all test cases doesn't exceed 300000 .
Output For each test case, output three integers vmax , l , and r — the maximum submedian vmax and the bounds of a subarray of length at least k (r−l+1≥k ) such that vmax is one of its medians.
If there are many solutions, you can print any of them.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.