← Home
write a go solution for B. Parity and Sumtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputGiven an array a of n positive integers.In one operation, you can pick any pair of indexes (i,j) such that a_i and a_j have distinct parity, then replace the smaller one with the sum of them. More formally:   If a_i<a_j, replace a_i with a_i+a_j;  Otherwise, replace a_j with a_i+a_j. Find the minimum number of operations needed to make all elements of the array have the same parity.InputThe first line contains a single integer t (1<=t<=10^4) — the number of test cases.The first line of each test case contains a single integer n (1<=n<=2*10^5).The second line contains n integers a_1,a_2,ldots,a_n (1<=a_i<=10^9) — the elements of array a.It is guaranteed that the sum of n over all test cases does not exceed 2*10^5.OutputFor each test case, output a single integer — the minimum number of operations required.ExampleInput751 3 5 7 944 4 4 432 3 443 2 2 864 3 6 1 2 163 6 1 2 1 25999999996 999999997 999999998 999999999 1000000000Output0
0
2
4
3
3
3
NoteIn the first test case, all integers already have the same parity. Therefore, no operation is needed.In the third test case, we can perform two operations (1,2) and (1,3). The array a transforms as follows: a=[colorred2,colorred3,4]longarrow[colorred5,3,colorred4]longarrow[5,3,9].In the fourth test case, an example of an optimal sequence of operations is (1,2), (1,3), (1,4), and (1,4). The array a transforms as follows: a=[colorred3,colorred2,2,8]longarrow[colorred3,5,colorred2,8]longarrow[colorred3,5,5,colorred8]longarrow[colorred11,5,5,colorred8]longarrow[11,5,5,19].. Output only the code with no comments, explanation, or additional text.