Gulabjamuns

3

2 votes
Easy
Problem

Rohan loves gulabjamuns a lot, but he has a strage habit. Whenever someone gets him gulabjamuns to eat, he stores them so that he can eat them later.

Recently his best friend Sonu gifted him N boxes of gulabjamun each containing Gi gulabjamuns where Gi represents the total number of gulabjamuns in the ith number box. Rohan wants to store them in a single box of some bigger size. The only constraint is that he can choose any two boxes and store their joint contents in an empty box only. Assume that there are infinite number of empty boxes available.

At a time he can pick up any two boxes of his choice for transferring and if suppose both the boxes contains X and Y number of gulabjamuns respectively, then it takes him exactly X+Y seconds of time.

As he is to eager to collect all of them he has approached you to tell him the difference between the minimum and maximum time in which all the gulabjamuns can be collected.

Input Format:

First line of input is number of test cases T. Each test case is comprised of two inputs First input of a test case is the number of boxes N Second input is N integers delimited by whitespace denoting number of gulabjamuns in each box.

Output Format:

For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is the difference between the minimum and maximum time in seconds.

Constraints:

1 ≤ T ≤ 10
1 ≤ N ≤ 1000
1 ≤ [Gulabjamuns in each box] ≤ 10000

Time Limit: 0.5
Memory Limit: 256
Source Limit:
Explanation

There are a total of 4 boxes, each containing 1, 2, 3 and 4 candies.

For finding out the minimum time :

Adding 1 + 2 in a new box takes 3 seconds
Adding 3 + 3 in a new box takes 6 seconds
Adding 4 + 6 in a new box takes 10 seconds
Hence total time taken is 19 seconds.

There can be other combinations also, but among all the possibilities the minimum time required is 19 seconds.

And for finding out the minimum time :

Adding 3 + 4 in a new box takes 7 seconds
Adding 2 + 7 in a new box takes 9 seconds
Adding 1 + 9 in a new box takes 10 seconds
Hence total time taken is 26 seconds.

There can be other combinations also, but among all the possibilities the maximum time required is 26 seconds.

Hence the the answer is the difference between the two time we find out.

Editor Image

?