C. Median Splits
binary search; greedy; implementation; sortings
The median of an array \(b_1, b_2, \ldots b_m\), written as \(\operatorname{med}(b_1, b_2, \ldots, b_m)\), is the \(\left\lceil \frac{m}{2} \right\rceil\)-th\(^{\text{∗}}\) smallest element of array \(b\).You are given an array of integers \(a_1, a_2, \ldots, a_n\) and an integer \(k\). You need to determine whether there exists a pair of indices \(1 \le l < r < n\) such that:$$$\(\operatorname{med}(\operatorname{med}(a_1, a_2, \ldots, a_l), \operatorname{med}(a_{l+1}, a_{l+2}, \ldots, a_r), \operatorname{med}(a_{r+1}, a_{r+2}, \ldots, a_n)) \le k.\)\(In other words, determine whether it is possible to split the array into three contiguous subarrays\)^{\text{†}}\( such that the median of the three subarray medians is less than or equal to \)k\(.\)^{\text{∗}}$$$\(\lceil x \rceil\) is the ceiling function which returns the least integer greater than or equal to \(x\).\(^{\text{†}}\)An array \(x\) is a subarray of an array \(y\) if \(x\) can be obtained from \(y\) by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.
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\) and \(k\) (\(3 \le n \le 2 \cdot 10^5\), \(1 \le k \le 10^9\)) — the length of the array \(a\) and the constant \(k\).The second line of each test case contains \(n\) integers \(a_1, a_2, \ldots, a_n\) (\(1 \le a_i \le 10^9\)) — the elements of the array \(a\).It is guaranteed that the sum of \(n\) over all test cases does not exceed \(2 \cdot 10^5\).
For each testcase, output ""YES"" if such a split exists, and ""NO"" otherwise.You can output the answer in any case (upper or lower). For example, the strings ""yEs"", ""yes"", ""Yes"", and ""YES"" will be recognized as positive responses.
In the first and second test case, the only possible partition of the array into three contiguous subarrays is \([3]\), \([2]\), \([1]\). Their respective medians are \(3\), \(2\), and \(1\). The median of the three subarray medians is \(\operatorname{med}(3, 2, 1) = 2\). Therefore, the answer for the first test case is ""YES"" since \(2\le 2\), while the answer for the second test case is ""NO"" since \(2 > 1\).In the third test case, it can be proven that no partition satisfies the constraints.In the fourth test case, one of the partitions satisfying the constraints is \([10, 7]\), \([12, 16, 3, 15]\), \([6, 11]\). The respective medians of subarrays are \(7\), \(12\), and \(6\). The median of the three subarray medians is \(\operatorname{med}(7, 12, 6) = 7 \le k\), hence this partition satisfies the constraints.In the fifth test case, one of the partitions satisfying the constraints is \([7, 11]\), \([12, 4]\), \([9, 17]\). The respective medians of the subarrays are \(7\), \(4\), and \(9\). The median of the three subarray medians is \(\operatorname{med}(7, 4, 9) = 7 \le k\), hence this partition satisfies the constraints.In the sixth test case, the only possible partition of the array into three contiguous subarrays is \([1000]\), \([10^9]\), \([1000]\). The respective medians of the subarrays are \(1000\), \(10^9\), and \(1000\). The median of the three subarray medians is \(\operatorname{med}(1000, 10^9, 1000) = 1000 \le k\), hence this partition satisfies the constraints.