logo AlgoBeat OnlineJudge
登录 注册

#214156. [SDCPC 2019] Stones in the Bucket

内存限制:256 MiB 时间限制:2000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

There are buckets on the ground, where the -th bucket contains stones. Each time one can perform one of the following two operations:

  • Remove a stone from one of the non-empty buckets.
  • Move a stone from one of the buckets (must be non-empty) to any other bucket (can be empty).

What's the minimum number of times one needs to perform the operations to make all the buckets contain the same number of stones?

输入格式

There are multiple test cases. The first line of the input contains an integer , indicating the number of test cases. For each test case:

The first line contains an integer (), indicating the number of buckets.

The second line contains integers (), indicating the number of stones in the buckets.

It's guaranteed that the sum of of all test cases will not exceed .

输出格式

For 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.

样例

样例输入 1

4
3
1 1 0
4
2 2 2 2
3
0 1 4
1
1000000000

样例输出 1

2
0
3
0

数据范围与提示

For 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.