Codeforces Global Round 30 (Div. 1 + Div. 2)
A
Sequence Game
Codeforces
800
原题
←B →
翻译中…

Given an integer sequence of length $n$ denoted as $a_1,a_2,\ldots,a_n$ and an integer $x$.

翻译中…

You can perform the following operation: select two adjacent numbers $a_i$ and $a_{i+1}$ and replace them with an integer $y$, which satisfies $\min(a_i,a_{i+1}) \le y \le \max(a_i,a_{i+1})$. After the replacement, the original $a_i$ and $a_{i+1}$ are removed from the sequence, and the elements are renumbered from $1$ to $n-1$.

翻译中…

For example, for $a=[1,2,4,5]$ you can select $a_2=2$ and $a_3=4$, and replace them with $3$. After that, $a$ becomes $[1,3,5]$. However, you cannot select $a_1=1$ and $a_2=2$ and replace them with $3$ (since $y$ is bigger than $\max(a_i,a_{i+1})$, nor can you select $a_1=1$ and $a_3=4$ (the selected numbers should be adjacent).

翻译中…

Clearly, after performing $n-1$ operations, only one number will remain. The question is whether this final number can be exactly equal to $x$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $T$ ($1 \le T \le 500$). The description of the test cases follows.

翻译中…

The first line of each test case contains one integer $n$ ($1 \le n \le 100$).

翻译中…

The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ($-10^9 \le a_i \le 10^9$).

翻译中…

The third line of each test case contains one integer $x$ ($-10^9 \le x \le 10^9$).

翻译中…

Output

翻译中…

For each test case, output "YES" (without quotes) if the final number can be exactly equal to $x$, and "NO" otherwise.

翻译中…

You can output "YES" and "NO" in any case (for example, strings "yES", "yes" and "Yes" will be recognized as a positive response).

翻译中…

Note

翻译中…

In the first test case, you can first select $a_2=7$ and $a_3=5$, and replace them with $6$. After that, $a$ becomes $[2, 6]$. Now you can select $a_1=2$ and $a_2=6$, and replace them with $4$.

翻译中…

In the second test case, it can be shown that the final number can never be $8$.

翻译中…

样例

Input #1
3
3
2 7 5
4
5
-1 3 7 -9 -2
8
6
1 -1 -4 5 1 -4
-2
Output #1
YES
NO
YES
InputCopy OutputCopy
题目信息
题号
2164A
时间限制
1 s
内存限制
256 MB
标签
暴力
排序

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