CF2103C Median Splits
Description
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 $ $ 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 \dots a_l), \operatorname{med}(a_{l + 1}, a_{l + 2} \dots a_r), \operatorname{med}(a_{r + 1}, a_{r + 2} \dots a_n)) \leq k.
$$
In other words, determine whether it is possible to split the array into three contiguous subarrays
such that the median of the three subarray medians is less than or equal to $k$.
Input Format
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 $ .
Output Format
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.
Explanation/Hint
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.