#K49822. Equalizing Tiles

    ID: 28728 Type: Default 1000ms 256MiB

Equalizing Tiles

Equalizing Tiles

You are given several test cases. In each test case, you are provided with an integer N representing the number of tiles and a list of N integers which denote the heights of these tiles. In one operation, you can reduce the height of any tile by 1. Your goal is to equalize the heights of all tiles by only lowering them.

To minimize the number of operations, you should lower every tile to the minimum height present in that test case. If the minimum height is m and the height of a tile is h, then the number of operations needed for that tile is h - m. The total operations for the test case is given by:

operations=i=1N(him)\text{operations} = \sum_{i=1}^{N}(h_i - m)

Your task is to compute and output the minimum number of operations required for each test case.

inputFormat

The input starts with an integer T, the number of test cases. Each test case follows with two lines. The first line contains an integer N representing the number of tiles. The second line contains N space-separated integers denoting the height of each tile.

outputFormat

For each test case, output a single integer on a new line representing the minimum number of operations required to equalize all tile heights.## sample

1
3
2 2 3
1