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.

saiujwal13083 | 155 |

vt9941 | 150 |

sanchit496 | 109 |

swapnilrawat2017 | 96 |

devesh_goyal | 95 |

saiujwal13083 | 414 |

generic_coder | 304 |

vt9941 | 274 |

ppsvikhyat17 | 244 |

meetpatel0963 | 202 |

Ibrahim Nash | 5438 |

blackshadows | 5428 |

akhayrutdinov | 5111 |

mb1973 | 4976 |

Quandray | 4752 |

Login to report an issue on this page.