欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1676B.Equal Candies
Equal Candies
There are boxes with different quantities of candies in each of them. The -th box has candies inside.
You also have 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?
Input
The first line contains an integer () — the number of test cases.
The first line of each test case contains an integer () — the number of boxes you have.
The second line of each test case contains integers () — the quantity of candies in each box.
Output
For each test case, print a single integer denoting the minimum number of candies you have to eat to satisfy the requirements.
Note
For the first test case, you can eat candy from the second box, candies from the third box, candies from the fourth box and candies from the fifth box. Now the boxes have candies in them and you ate candies in total so the answer is .
For the second test case, the best answer is obtained by making all boxes contain candies in them, thus eating candies in total.
Samples
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
10
4975
38
0
0
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |