Fredo and Sums

3.3

21 votes
Algorithms, Arrays, Easy, Greedy Algorithms, Merge sort, Sorting
Problem

Fredo has an array A consisting of N elements. He wants to divide the array into pairs where each array element comes in exactly one pair. Say that pair i has elements and , he defines S as :

He asks you to find the minimum and maximum value of S.

Input Format:

First line consists of an integer T denoting the number of test cases.
Each test case:
First line consists of an integer N denoting the number of elements in the array.
Second line consists of N space separated integers denoting the array elements.

Output Format:
For each test case, print the minimum and maximum sum (space separated). Answer for each test case should come in a new line.

Input Constraints:




Sample Input
1
4
10 20 -10 0
Sample Output
20 40
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

For minimum sum, we take pairs and .
For maximum sum, we take pairs and .

Editor Image

?