Codeforces Round 1019 (Div. 2)
C
Median Splits
Codeforces
1600
原题
← BD →
翻译中…

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 \lt r \lt 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.

翻译中…

Input

翻译中…

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

翻译中…

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.

翻译中…

Note

翻译中…

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 \gt 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.

翻译中…

样例

Input #1
6
3 2
3 2 1
3 1
3 2 1
6 3
8 5 3 1 6 4
8 7
10 7 12 16 3 15 6 11
6 8
7 11 12 4 9 17
3 500000000
1000 1000000000 1000
Output #1
YES
NO
NO
YES
YES
YES
InputCopy OutputCopy
题目信息
题号
2103C
时间限制
2 s
内存限制
256 MB
标签
二分
贪心
模拟
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。