P15759 [CodeChef] BAB I
普及-
题目描述

Chef gives an array A with N elements to Babla. Babla's task is to find the maximum non-negative integer X such that:

No element in the array belongs to the range [-X, X]. In other words, for all (1≤ i ≤ N), either A_{i} < -X or A_{i} > X.

Help Babla to find the maximum non-negative integer X for which the given condition is satisfied or determine if no such X exists.

------ Input Format ------

  • The first line of input will contain a single integer T, denoting the number of test cases.
  • Each test case consists of multiple lines of input.
  • The first line of each test case contains an integer N — the number of elements in the array.
  • The second line of each test case contains $N space-separated integers A_{1}, A_{2}, \ldots, A_{N}$ representing the array A.

------ Output Format ------

For each test case, output on a new line, the maximum non-negative integer X, satisfying the above condition.
If no such X exists, output -1 instead.

------ Constraints ------

$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$-10^{9} ≤ A_{i} ≤ 10^{9}$
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.

----- Sample Input 1 ------
3
5
8 4 2 5 2
6
7 9 -10 8 12 17
4
0 -3 -1 -10

----- Sample Output 1 ------
1
6
-1

----- explanation 1 ------
Test case $1$: The maximum value of $X$ such that no element of the array belongs to the range $[-X, X]$ is $1$. All elements of the array are strictly greater than $1$.

Test case $2$: The maximum value of $X$ such that no element of the array belongs to the range $[-X, X]$ is $6$. All positive elements of the array are strictly greater than $6$ and negative elements are strictly less than $-6$.

Test case $3$: It is not possible to choose an element $X$ that satisfies the given condition.

输入格式

见题面

输出格式

见题面

样例输入
3 5 8 4 2 5 2 6 7 9 -10 8 12 17 4 0 -3 -1 -10
样例输出
1 6 -1