Codeforces Round 951 (Div. 2)
A
Guess the Maximum
Codeforces
800
原题
←B →
翻译中…

Alice and Bob came up with a rather strange game. They have an array of integers $a_1, a_2,\ldots, a_n$. Alice chooses a certain integer $k$ and tells it to Bob, then the following happens:

翻译中…
  • Bob chooses two integers $i$ and $j$ ($1 \le i \lt j \le n$), and then finds the maximum among the integers $a_i, a_{i + 1},\ldots, a_j$;
  • If the obtained maximum is strictly greater than $k$, Alice wins, otherwise Bob wins.
翻译中…

Help Alice find the maximum $k$ at which she is guaranteed to win.

翻译中…

Input

翻译中…

Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($2 \le n \le 5 \cdot 10^4$) — the number of elements in the array.

翻译中…

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.

翻译中…

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

翻译中…

Output

翻译中…

For each test case, output one integer — the maximum integer $k$ at which Alice is guaranteed to win.

翻译中…

Note

翻译中…

In the first test case, all possible subsegments that Bob can choose look as follows: $[2, 4], [2, 4, 1], [2, 4, 1, 7], [4, 1], [4, 1, 7], [1, 7]$. The maximums on the subsegments are respectively equal to $4, 4, 7, 4, 7, 7$. It can be shown that $3$ is the largest integer such that any of the maximums will be strictly greater than it.

翻译中…

In the third test case, the only segment that Bob can choose is $[1, 1]$. So the answer is $0$.

翻译中…

样例

Input #1
6
4
2 4 1 7
5
1 2 3 4 5
2
1 1
3
37 8 16
5
10 10 10 10 9
10
3 12 9 5 2 3 2 9 8 2
Output #1
3
1
0
15
9
2
InputCopy OutputCopy
题目信息
题号
1979A
时间限制
1 s
内存限制
256 MB
标签
暴力
贪心
模拟

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