Codeforces Round 1112 (Div. 2)
A
阈值移动
Threshold Movement
Codeforces
800
原题
←B →

阈值移动AI (CI翻译)

There are $n+2$ positions numbered from $0$ to $n+1$. Initially, position $i$ contains an element of weight $w_i$ for every $1\le i\le n$, while positions $0$ and $n+1$ are empty.

有 $n+2$ 个位置,编号为 $0$ 到 $n+1$。初始时,对于每个 $1\le i\le n$,位置 $i$ 中放有一个重量为 $w_i$ 的元素,而位置 $0$ 和 $n+1$ 为空。AI (CI翻译)

You choose an integer $k$. Then every element moves exactly once, simultaneously:

你需要选择一个整数 $k$。随后,所有元素同时且恰好移动一次:AI (CI翻译)

  • If $w_i \lt k$, the element at position $i$ moves to position $i-1$;
  • If $w_i \gt k$, the element at position $i$ moves to position $i+1$;
  • If $w_i=k$, the entire movement process fails immediately.
  • 如果 $w_i \lt k$,位置 $i$ 中的元素移动到位置 $i-1$;
  • 如果 $w_i \gt k$,位置 $i$ 中的元素移动到位置 $i+1$;
  • 如果 $w_i=k$,整个移动过程立即失败。
AI (CI翻译)

An integer $k$ is perfect if the movement does not fail and, upon completion, every position from $1$ to $n$ contains exactly one element.

如果移动过程没有失败,并且移动完成后位置 $1$ 到 $n$ 中的每个位置都恰好包含一个元素,则称整数 $k$ 是完美的。AI (CI翻译)

Determine whether a perfect integer $k$ exists.

请判断是否存在一个完美的整数 $k$。AI (CI翻译)

Input

输入格式

AI (CI翻译)

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.

每个测试包含多个测试用例。第一行包含测试用例的数量 $t$($1 \le t \le 500$)。接下来给出各测试用例的描述。AI (CI翻译)

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

每个测试用例的第一行包含一个整数 $n$($1\le n\le 100$)。AI (CI翻译)

The second line of each test case contains $n$ integers $w_1,w_2,\ldots,w_n$ ($1\le w_i\le 10^9$).

每个测试用例的第二行包含 $n$ 个整数 $w_1,w_2,\ldots,w_n$($1\le w_i\le 10^9$)。AI (CI翻译)

Output

输出格式

AI (CI翻译)

For each test case, print "YES" if a perfect integer $k$ exists, and "NO" otherwise.

对于每个测试用例,如果存在一个完美的整数 $k$,输出“YES”,否则输出“NO”。AI (CI翻译)

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.

你可以使用任意大小写形式输出答案。例如,字符串“yEs”、“yes”、“Yes”和“YES”都会被识别为肯定回答。AI (CI翻译)

Note

说明

AI (CI翻译)

In the first test case, the only element either leaves position $1$ or has weight equal to $k$, so no suitable integer exists.

在第一个测试用例中,唯一的元素要么离开位置 $1$,要么重量等于 $k$,因此不存在合适的整数。AI (CI翻译)

In the second test case, choose $k=2$. The element of weight $3$ moves right and the element of weight $1$ moves left, leaving one element in each position.

在第二个测试用例中,选择 $k=2$。重量为 $3$ 的元素向右移动,重量为 $1$ 的元素向左移动,移动后每个位置都恰好有一个元素。AI (CI翻译)

In the third test case, keeping both positions occupied would require $1 \lt k \lt 2$, which is impossible for an integer $k$.

在第三个测试用例中,若要保持两个位置都有元素,就必须满足 $1 \lt k \lt 2$,但这对于整数 $k$ 来说是不可能的。AI (CI翻译)

In the fourth test case, $k=5$ is suitable: the elements at positions $1$ and $3$ move right, while those at positions $2$ and $4$ move left. Upon completion, every position from $1$ to $4$ contains exactly one element.

在第四个测试用例中,$k=5$ 是合适的选择:位置 $1$ 和 $3$ 的元素向右移动,而位置 $2$ 和 $4$ 的元素向左移动。移动完成后,位置 $1$ 到 $4$ 的每个位置都恰好包含一个元素。AI (CI翻译)

In the fifth test case, the element at position $2$ must move left, requiring $k \gt 8$, while the element at position $3$ must move right, requiring $k \lt 7$. These requirements are incompatible.

在第五个测试用例中,位置 $2$ 的元素必须向左移动,因此要求 $k \gt 8$;而位置 $3$ 的元素必须向右移动,因此要求 $k \lt 7$。这两个条件互相矛盾。AI (CI翻译)

In the sixth test case, choose $k=4$. All elements at odd positions move right and all elements at even positions move left, so every position from $1$ to $6$ contains one element afterwards.

在第六个测试用例中,选择 $k=4$。所有奇数位置的元素向右移动,所有偶数位置的元素向左移动,因此移动后位置 $1$ 到 $6$ 的每个位置都恰好包含一个元素。AI (CI翻译)

样例

Input #1
6
1
7
2
3 1
2
2 1
4
9 1 7 2
4
9 8 7 1
6
1000000000 1 9 2 8 3
Output #1
NO
YES
NO
YES
NO
YES
InputCopy OutputCopy
题目信息
题号
2250A
时间限制
1 s
内存限制
256 MB
标签
暴力
模拟
数学

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