
ZOJ Problem Set  4118
There are $n$ buckets on the ground, where the $i$th bucket contains $a_i$ stones. Each time one can perform one of the following two operations:
What's the minimum number of times one needs to perform the operations to make all the buckets contain the same number of stones? InputThere are multiple test cases. The first line of the input contains an integer $T$, indicating the number of test cases. For each test case: The first line contains an integer $n$ ($1 \le n \le 10^5$), indicating the number of buckets. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^9$), indicating the number of stones in the buckets. It's guaranteed that the sum of $n$ of all test cases will not exceed $10^6$. OutputFor each test case output one line containing one integer, indicating the minimum number of times needed to make all the buckets contain the same number of stones. Sample Input4 3 1 1 0 4 2 2 2 2 3 0 1 4 1 1000000000 Sample Output2 0 3 0 HintFor the first sample test case, one can remove all the stones in the first two buckets. For the second sample test case, as all the buckets have already contained the same number of stones, no operation is needed. For the third sample test case, one can move 1 stone from the 3rd bucket to the 1st bucket and then remove 2 stones from the 3rd bucket. Author: WENG, Caizhi Source: The 10th Shandong Provincial Collegiate Programming Contest 