CF2021A.Meaning Mean

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Meaning Mean

Pak Chanek has an array aa of nn positive integers. Since he is currently learning how to calculate the floored average of two numbers, he wants to practice it on his array aa.

While the array aa has at least two elements, Pak Chanek will perform the following three-step operation:

  1. Pick two different indices ii and jj (1i,ja1 \leq i, j \leq |a|; iji \neq j), note that a|a| denotes the current size of the array aa.
  2. Append ai+aj2\lfloor \frac{a_i+a_j}{2} \rfloor^{\text{∗}} to the end of the array.
  3. Remove elements aia_i and aja_j from the array and concatenate the remaining parts of the array.

For example, suppose that a=[5,4,3,2,1,1]a=[5,4,3,2,1,1]. If we choose i=1i=1 and j=5j=5, the resulting array will be a=[4,3,2,1,3]a=[4,3,2,1,3]. If we choose i=4i=4 and j=3j=3, the resulting array will be a=[5,4,1,1,2]a=[5,4,1,1,2].

After all operations, the array will consist of a single element xx. Find the maximum possible value of xx if Pak Chanek performs the operations optimally.

^{\text{∗}}x\lfloor x \rfloor denotes the floor function of xx, which is the greatest integer that is less than or equal to xx. For example, 6=6\lfloor 6 \rfloor = 6, 2.5=2\lfloor 2.5 \rfloor=2, 3.6=4\lfloor -3.6 \rfloor=-4 and π=3\lfloor \pi \rfloor=3

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t50001 \le t \le 5000). The description of the test cases follows.

The first line of each test case contains a single integer nn (2n502 \le n \le 50) — the length of the array aa.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai1091 \le a_i \le 10^9) — the elements of the array aa.

Do note that the sum of nn over all test cases is not bounded.

Output

For each test case, output a single integer: the maximum possible value of xx after all numbers have been picked.

Note

In the first test case, the array is initially a=[1,7,8,4,5]a=[1,7,8,4,5]. Pak Chanek will perform the following operations:

  1. Pick i=1i=1 and j=2j=2, then a=[8,4,5,4]a=[8,4,5,4].
  2. Pick i=3i=3 and j=2j=2, then a=[8,4,4]a=[8,4,4].
  3. Pick i=2i=2 and j=3j=3, then a=[8,4]a=[8,4].
  4. Pick i=1i=1 and j=2j=2, then a=[6]a=[6].

After all the operations, the array consists of a single element x=6x=6. It can be proven that there is no series of operations that results in xx greater than 66 in the end.

Samples

3
5
1 7 8 4 5
3
2 6 5
5
5 5 5 5 5
6
4
5

在线编程 IDE

建议全屏模式获得最佳体验