MoEngage has given you an array
of integers and a positive integer .
You can apply the following operation on the array any number of times. In one operation:
- Choose a strictly increasing array of length such that:
- and for all ;
- for all .
- Subtract from for all .
The cost of this operation is .
Note that, can be different for different operations.
Let be the total cost after performing number of operations on the array. Your goal is to maximize the value of .
Input Format
- First line contains a single integer , denoting the number of test cases.
- For each of the test cases, the first line contains two integers and .
- The next line contains space-separated integers denoting .
Output Format
For each test case, output a single integer - the maximum value of .
Constraints
- Sum of over all test cases does not exceed .
Sample Input 1
3
3 3
3 1 5
7 5
5 5 5 4 1 2 1
2 10
3 3
Sample Output 1
1
0
27
Explanation
Test case : Given , , .
It is optimal to apply only operation with . The cost for the operation would be . The value of and the total cost . Thus, .
After the operation, the array becomes .Test case : Given , , .
It can be proven that it is never optimal to apply any operation. Hence, the answer will be .Test case : Given , , .
It is optimal to apply operations on the array. In each operation, it is optimal to take . The cost for each operation would be . Thus, and total cost . Thus, .
After all the operations, the array becomes .
ConversionConversion EmoticonEmoticon