Problem of the day
Suppose ‘N’ = 3, and ‘A’ = [7, 1, 8]
The optimal order for mining diamonds will be [2, 1, 3].
State of mine - [7, 1, 8] [7, 8] [8]
Coins earned - (7*1*8) + (1*7*8) + (1*8*1) = 56 + 56 + 8 = 120
Hence output will be 120.
The first line of the input contains a single integer ‘T’ representing the no. of test cases.
The first line of each test case contains a single integer value, ‘N’, denoting the number of diamonds in the mine.
The second line of each test case contains ‘N’ space-separated integers, denoting the size of the diamonds in the mine.
For each test case, print a single integer value denoting the maximum number of coins that can be earned by mining the diamonds in an optimal order.
Print a separate line for each test case.
You are not required to print anything; it has already been taken care of. Just implement the function and return the answer.
1 ≤ T ≤ 100
1 ≤ N ≤ 100
0 ≤ A[i] ≤ 100
1 ≤ ΣN ≤ 300
Time limit: 1 Sec
2
3
7 1 8
2
9 1
120
18
For First Case - Same as explained in above example.
For the second case -
‘N’ = 2, and ‘A’ = [9, 1]
The optimal order for mining diamonds will be [2, 1].
State of mine - [9, 1] [9]
Coins earned - (1*9*1) + (1*9*1) = 9 + 9 = 18
Hence output will be 18..
2
5
1 2 3 4 5
4
1 5 2 8
110
136