CF1946A.Median of an Array

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

Median of an Array

You are given an array aa of nn integers.

The median of an array q1,q2,,qkq_1, q_2, \ldots, q_k is the number pk2p_{\lceil \frac{k}{2} \rceil}, where pp is the array qq sorted in non-decreasing order. For example, the median of the array [9,5,1,2,6][9, 5, 1, 2, 6] is 55, as in the sorted array [1,2,5,6,9][1, 2, 5, 6, 9], the number at index 52=3\lceil \frac{5}{2} \rceil = 3 is 55, and the median of the array [9,2,8,3][9, 2, 8, 3] is 33, as in the sorted array [2,3,8,9][2, 3, 8, 9], the number at index 42=2\lceil \frac{4}{2} \rceil = 2 is 33.

You are allowed to choose an integer ii (1in1 \le i \le n) and increase aia_i by 11 in one operation.

Your task is to find the minimum number of operations required to increase the median of the array.

Note that the array aa may not necessarily contain distinct numbers.

Input

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

The first line of each test case contains a single integer nn (1n1051 \le n \le 10^5) — 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 array aa.

It is guaranteed that the sum of the values of nn over all test cases does not exceed 21052 \cdot 10^5.

Output

For each test case, output a single integer — the minimum number of operations required to increase the median of the array.

Note

In the first test case, you can apply one operation to the first number and obtain the array [3,2,8][3, 2, 8], the median of this array is 33, as it is the number at index 32=2\lceil \frac{3}{2} \rceil = 2 in the non-decreasing sorted array [2,3,8][2, 3, 8]. The median of the original array [2,2,8][2, 2, 8] is 22, as it is the number at index 32=2\lceil \frac{3}{2} \rceil = 2 in the non-decreasing sorted array [2,2,8][2, 2, 8]. Thus, the median increased (3>23 \gt 2) in just one operation.

In the fourth test case, you can apply one operation to each of the numbers at indices 1,2,31, 2, 3 and obtain the array [6,6,6,4,5][6, 6, 6, 4, 5], the median of this array is 66, as it is the number at index 52=3\lceil \frac{5}{2} \rceil = 3 in the non-decreasing sorted array [4,5,6,6,6][4, 5, 6, 6, 6]. The median of the original array [5,5,5,4,5][5, 5, 5, 4, 5] is 55, as it is the number at index 52=2\lceil \frac{5}{2} \rceil = 2 in the non-decreasing sorted array [4,5,5,5,5][4, 5, 5, 5, 5]. Thus, the median increased (6>56 \gt 5) in three operations. It can be shown that this is the minimum possible number of operations.

In the fifth test case, you can apply one operation to each of the numbers at indices 1,31, 3 and obtain the array [3,1,3,3,1,4][3, 1, 3, 3, 1, 4], the median of this array is 33, as it is the number at index 62=3\lceil \frac{6}{2} \rceil = 3 in the non-decreasing sorted array [1,1,3,3,3,4][1, 1, 3, 3, 3, 4]. The median of the original array [2,1,2,3,1,4][2, 1, 2, 3, 1, 4] is 22, as it is the number at index 62=3\lceil \frac{6}{2} \rceil = 3 in the non-decreasing sorted array [1,1,2,2,3,4][1, 1, 2, 2, 3, 4]. Thus, the median increased (3>23 \gt 2) in two operations. It can be shown that this is the minimum possible number of operations.

Samples

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

在线编程 IDE

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