Codeforces Round 947 (Div. 1 + Div. 2)
C
Chamo and Mocha's Array
Codeforces
1200
原题
← BD →
翻译中…

Mocha likes arrays, so before her departure, Chamo gave her an array $a$ consisting of $n$ positive integers as a gift.

翻译中…

Mocha doesn't like arrays containing different numbers, so Mocha decides to use magic to change the array. Mocha can perform the following three-step operation some (possibly, zero) times:

翻译中…
  1. Choose indices $l$ and $r$ ($1 \leq l \lt r \leq n$)
  2. Let $x$ be the median$^\dagger$ of the subarray $[a_l, a_{l+1},\ldots, a_r]$
  3. Set all values $a_l, a_{l+1},\ldots, a_r$ to $x$
翻译中…

Suppose $a=[1,2,3,4,5]$ initially:

翻译中…
  • If Mocha chooses $(l,r)=(3,4)$ in the first operation, then $x=3$, the array will be changed into $a=[1,2,3,3,5]$.
  • If Mocha chooses $(l,r)=(1,3)$ in the first operation, then $x=2$, the array will be changed into $a=[2,2,2,4,5]$.
翻译中…

Mocha will perform the operation until the array contains only the same number. Mocha wants to know what is the maximum possible value of this number.

翻译中…

$^\dagger$ The median in an array $b$ of length $m$ is an element that occupies position number $\lfloor \frac{m+1}{2} \rfloor$ after we sort the elements in non-decreasing order. For example, the median of $[3,1,4,1,5]$ is $3$ and the median of $[5,25,20,24]$ is $20$.

翻译中…

Input

翻译中…

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

翻译中…

The first line of each test case contains a single integer $n$ ($2\leq n\leq 10^5$) — the length of the array $a$.

翻译中…

The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ($1\leq a_i \leq 10^9$) — the elements of the array $a$.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^5$.

翻译中…

Output

翻译中…

For each test case, output the maximum value of the number.

翻译中…

Note

翻译中…

In the first test case, $a=[1,2]$. Mocha can only choose the interval $(l,r)=(1,2)$. The array will be changed to $a=[1,1]$. Therefore, the answer is $1$.

翻译中…

In the second test case, Mocha can perform the following operations:

翻译中…
  • Choose the interval $(l,r)=(4,5)$, then $a=[1,2,3,4,4]$.
  • Choose the interval $(l,r)=(3,5)$, then $a=[1,2,4,4,4]$.
  • Choose the interval $(l,r)=(1,5)$, then $a=[4,4,4,4,4]$.
翻译中…

The array contains only the same number, which is $4$. It can be proven that the maximum value of the final number cannot be greater than $4$.

翻译中…

样例

Input #1
2
2
1 2
5
1 2 3 4 5
Output #1
1
4
InputCopy OutputCopy
题目信息
题号
1975C
时间限制
2 s
内存限制
256 MB
标签
二分
暴力
贪心

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