#K74157. Minimum Operations to Equalize Array Elements

    ID: 34135 Type: Default 1000ms 256MiB

Minimum Operations to Equalize Array Elements

Minimum Operations to Equalize Array Elements

You are given T test cases. For each test case, you are provided with an integer (N) representing the number of elements in the array, followed by (N) integers. In one operation, you can increment an element by 1. The goal is to make all elements equal using the minimum number of operations. The optimal strategy is to raise every element to the maximum value present in the array. Mathematically, the minimum number of operations required to equalize the array is (\sum_{i=1}^{N} (\max(a) - a_i)), where (a_i) represents each element in the array and (\max(a)) is the maximum element in the array.

Note: The input is read from standard input (stdin) and the output is written to standard output (stdout).

inputFormat

The first line of input contains a single integer T, the number of test cases. For each test case:

  • The first line contains an integer N, the number of elements in the array.
  • The second line contains N space-separated integers representing the array elements.

For example:

3 3 1 2 3 4 1 1 1 1 5 1 2 3 4 5

outputFormat

For each test case, output a single line containing the minimum number of operations required to make all elements equal.## sample

1
3
1 2 3
3