CF1676B.Equal Candies
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n boxes with different quantities of candies in each of them. The i-th box has ai candies inside.
You also have n friends that you want to give the candies to, so you decided to give each friend a box of candies. But, you don't want any friends to get upset so you decided to eat some (possibly none) candies from each box so that all boxes have the same quantity of candies in them. Note that you may eat a different number of candies from different boxes and you cannot add candies to any of the boxes.
What's the minimum total number of candies you have to eat to satisfy the requirements?
有 n 个盒子,每个盒子中装有不同数量的糖果。第 i 个盒子中有 ai 颗糖果。
你还有 n 位朋友,打算将这些糖果分给他们,因此你决定给每位朋友分配一个装有糖果的盒子。但你不想让任何朋友感到不快,于是你决定从每个盒子中吃掉一些(可能为零)糖果,使得所有盒子中剩余的糖果数量都相同。注意:你可以从不同的盒子中吃掉不同数量的糖果,但不能向任何一个盒子中添加糖果。
为满足上述要求,你需要吃掉的糖果总数的最小值是多少?
输入格式
The first line contains an integer t (1≤t≤1000) — the number of test cases.
The first line of each test case contains an integer n (1≤n≤50) — the number of boxes you have.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤107) — the quantity of candies in each box.
第一行包含一个整数 t(1≤t≤1000)——测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤50)——你拥有的盒子数量。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤107)——每个盒子中的糖果数量。
输出格式
For each test case, print a single integer denoting the minimum number of candies you have to eat to satisfy the requirements.
对于每个测试用例,输出一个整数,表示为满足要求所需吃的最少糖果数量。
输入输出样例
输入#1
5 5 1 2 3 4 5 6 1000 1000 5 1000 1000 1000 10 1 2 3 5 1 2 7 9 13 5 3 8 8 8 1 10000000
输出#1
10 4975 38 0 0
说明/提示
For the first test case, you can eat 1 candy from the second box, 2 candies from the third box, 3 candies from the fourth box and 4 candies from the fifth box. Now the boxes have [1,1,1,1,1] candies in them and you ate 0+1+2+3+4=10 candies in total so the answer is 10.
For the second test case, the best answer is obtained by making all boxes contain 5 candies in them, thus eating 995+995+0+995+995+995=4975 candies in total.
对于第一个测试用例,你可以从第二个盒子中吃掉 1 颗糖果,从第三个盒子中吃掉 2 颗糖果,从第四个盒子中吃掉 3 颗糖果,从第五个盒子中吃掉 4 颗糖果。此时各盒子中的糖果数量变为 [1,1,1,1,1],而你总共吃掉了 0+1+2+3+4=10 颗糖果,因此答案为 10。
对于第二个测试用例,最优方案是使所有盒子均含有 5 颗糖果,因此总共吃掉的糖果数为 995+995+0+995+995+995=4975。
输入解题思路,AI测评打分。不知道怎么写?