Shuffling Parities solution codechef

Shuffling Parities solution codechef

For Solution

Click Here!

Chef is given an array AA consisting of NN positive integers. Chef shuffles the array AA and creates a new array BB of length NN, where Bi=(Ai+i)mod2Bi=(Ai+i)mod2, for each i(1iN)i(1≤i≤N).

Find the maximum possible sum of integers of the array BB, if Chef shuffles the array AA optimally.

Input Format Shuffling Parities solution codechef

  • The first line of the input contains a single integer TT denoting the number of test cases. The description of TT test cases follows.
  • Each test case contains two lines of input.
  • The first line of each test case contains an integer NN.
  • The second line of each test case contains NN space-separated integers A1,A2,,ANA1,A2,…,AN.

Output Format

For each test case, print a single line containing one integer – the maximum sum of integers of the array BB.

Constraints Shuffling Parities solution codechef

  • 1T1041≤T≤104
  • 1N1051≤N≤105
  • 1Ai1091≤Ai≤109
  • Sum of NN over all test cases does not exceed 31053⋅105.

Subtasks

Subtask #1 (100 points): Original constraints

Sample Input 1  Shuffling Parities solution codechef 

3
3
1 2 3
3
2 4 5
2
2 4

Sample Output 1 

2
3
1

Explanation

Test case 11: One of the optimal ways to shuffle the array AA is [2,1,3][2,1,3]. Then the array B=[(2+1)mod2,(1+2)mod2,(3+3)mod2]=[1,1,0]B=[(2+1)mod2,(1+2)mod2,(3+3)mod2]=[1,1,0]. So the sum of integers of array BB is 22. There is no other possible way to shuffle array AA such that the sum of integers of array BB becomes greater than 22.

Test case 22: One of the optimal ways shuffle the array AA is [2,5,4][2,5,4]. Then the array B=[(2+1)mod2,(5+2)mod2,(4+3)mod2]=[1,1,1]B=[(2+1)mod2,(5+2)mod2,(4+3)mod2]=[1,1,1]. So the sum of integers of array BB is 33 .

For Solution

Click Here!

Leave a Comment

Your email address will not be published.