#C8541. Equalizing Tree Heights with Minimum Spells
Equalizing Tree Heights with Minimum Spells
Equalizing Tree Heights with Minimum Spells
In this problem, you are given multiple test cases where each test case provides the number of trees and their corresponding heights. In one spell, you may increase the height of any tree by 1. Your task is to determine the minimum number of spells needed to make all trees in a test case have the same height. Mathematically, if a test case contains N trees with heights (h_1, h_2, \ldots, h_N) and (M = \max{h_1, h_2, \ldots, h_N}), then the answer is given by:
[ \sum_{i=1}^{N} (M - h_i) ]
Make sure to read input from standard input (stdin) and write the result to standard output (stdout).
inputFormat
The input begins with an integer (T) representing the number of test cases. For each test case, the first line contains an integer (N), the number of trees. The second line contains (N) space-separated integers representing the heights of the trees.
outputFormat
For each test case, output a single line containing one integer — the minimum number of spells required to equalize the heights of all trees.## sample
1
3
1 2 3
3