
Let’s say you have three piles of stones of sizes 3, 4, and 2 respectively.
We can choose pile 1 and pile 2 three times. This will make our score 3. The piles will now contain 0, 1, and 2 stones respectively. We can now choose pile 2 and pile 3 one time. This will make our score 4. The piles will now contain 0, 0, and 1 stone respectively. Since there are no two different non-empty piles of stones game comes to an end. Therefore the answer is 4.
The first line contains a single integer ‘T’ representing the number of test cases. The 'T' test cases follow.
The only line of each test case contains three space-separated integers ‘num1’,’num2’, and ‘num3’ representing the size of three piles of stones for which you need to return the maximum score.
For each test case, print an integer denoting the maximum score you can get.
You do not need to print anything; it has already been taken care of. Just implement the function.
1 <= T <= 10000
1 <= ‘num1’ <= 10^5
1 <= ‘num2’ <= 10^5
1 <= ‘num3’ <= 10^5
Time Limit: 1sec
As we need to maximize the score we need to think greedily. At every move, we will always choose the pile with the maximum number of stones and the pile with the second maximum number of stones. This approach will always lead to the maximum score. We can use a priority queue/heap to implement this approach :
We can implement the approach as follows: