Given an array $$$a$$$ of $$$n$$$ integers and a non-negative integer $$$k$$$, find the maximum integer $$$X$$$ such that there exists at least one valid contiguous subarray $$$a[l..r]$$$ satisfying the following conditions :
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ $$$(1 \le t \le 10^4)$$$. The description of the test cases follows.
The first line of each test case contains two integers $$$n$$$ $$$(2 \le n \le 2 \cdot 10^5)$$$ and $$$k$$$ $$$(0 \le k \le 10^8)$$$.
The second line contains $$$n$$$ integers $$$a_1, a_2 ... a_n$$$ $$$(1 \le a_i \le 10^8)$$$.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, output a single integer $$$X$$$ that is the maximum integer satisfying the problem constraints.
53 1020 20 503 50100 5 1003 1000100 1 1003 10050 60 105 20100 10 100 10 100
20551005030
In the first test case, $$$a=[20,20,50]$$$, $$$k=10$$$. We choose the subarray $$$a[1…2]=[20,20]$$$ with target $$$X=20$$$.
Majority: Elements with value $$$\geq 20$$$ is $$$2$$$. Count is $$$2$$$, Length is $$$2$$$. Since Length $$$ \gt 1$$$ (more than half the subarray length), the condition holds.
Cost: All elements are already $$$\geq 20$$$, the cost is $$$0$$$ which is $$$\le 10$$$. It is impossible to achieve $$$X \gt 20$$$. For example, if $$$X = 21$$$, the only element $$$\geq 21$$$ is $$$50$$$. Any subarray including $$$50$$$ (e.g., $$$[20,50]$$$ or $$$[20,20,50]$$$) would have a majority count of only $$$1$$$, which is not strictly greater than half the length.