Pair the minimum
Submissions: 3746   Accuracy:

28.95%

  Difficulty: Easy   Marks: 2

Akshay loves to play with numbers and arrays. He took an array of size " 2n " where n is any positive integer chose by him. He tries to divide the array into n pairs, such that the pair sum minimizes the maximum sum of a pair. For example, say we have an array with the given numbers (9, 6, 1, and 5). The possible pairs are ( 1 , 6 ) , ( 5 , 9 ) or ( 1 , 5 )  , ( 6 , 9 ) or  ( 1 , 9 ) , ( 5 , 6 ). The pair sums for these partitions are ( 7 , 14 ) and ( 6 , 15 ) and ( 10 , 11 )  respectively .  The ideal or the selected pairs are (1, 9), (5, 6 )  because out of all the three cases or possibilities we only have (1, 9), (5, 6 )  where the sum of both pairs is minimum of all the maximum sum of all three possibilities. 

Input: 
 
The first Line contains an integer denoting the number of test cases.The first line of each test case contains integer n.The second line contains the array of size  2 * n, consisting of positive integers only.

Output:
For each test case, the output is the list of ideal pairs in the form (a,b)(c,d) and so on in newline. 

Constraints:
1<=T<=150
1<=N<=150
1 <= A[ 2*N ] <= 10^5

Examples:
Input
1
2
5 8 3 9

Output:
(3,9)(5,8)   

Explanation :  
Possible pairs: 
(8,9)(3,5) -->Case 1
Sum : (17)(8) --> maximum sum 17
(5,9)(3,8) -->Case 2
Sum : (14)(11) ----> maximum sum 14
(3,9)(5,8) -->Case 3
Sum : (12)(13)--> maximum sum 13
In case 3 , the maximum sum is minimum of all the other cases. Hence, the answer is(3,9)(5,8).

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Diksha Singhal
Author: diksha1812


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.