Timer is Running

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

**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).

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.

abnandi04 | 801 |

KshamaGupta | 562 |

mummy | 326 |

jagseersinghbe18cse | 296 |

ponnadasaikesav | 292 |

abnandi04 | 776 |

KshamaGupta | 446 |

yogesh_aka_dante | 288 |

ponnadasaikesav | 269 |

mummy | 239 |

blackshadows | 5362 |

Ibrahim Nash | 5244 |

akhayrutdinov | 5111 |

mb1973 | 4976 |

Quandray | 4748 |

Login to report an issue on this page.