There are nn boxes with different quantities of candies in each of them. The ii-th box has a_ia
i

candies inside.

You also have nn 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 tt (1 \leq t \leq 10001≤t≤1000) — the number of test cases.

The first line of each test case contains an integer nn (1 \leq n \leq 501≤n≤50) — the number of boxes you have.

The second line of each test case contains nn integers a_1, a_2, \dots, a_na
1

,a
2

,…,a
n

(1 \leq a_i \leq 10^71≤a
i

≤10
7
) — 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.

Sample 1
Inputcopy Outputcopy
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
Note
For the first test case, you can eat 11 candy from the second box, 22 candies from the third box, 33 candies from the fourth box and 44 candies from the fifth box. Now the boxes have [1, 1, 1, 1, 1][1,1,1,1,1] candies in them and you ate 0 + 1 + 2 + 3 + 4 = 100+1+2+3+4=10 candies in total so the answer is 1010.

For the second test case, the best answer is obtained by making all boxes contain 55 candies in them, thus eating 995 + 995 + 0 + 995 + 995 + 995 = 4975995+995+0+995+995+995=4975 candies in total.

#include<iostream>
using namespace std;
int main(void) {int n;cin >> n;int m;int a[1005];for (int i = 0; i < n; i++) {cin >> m;int minv = 1e8;int sum = 0;for (int j = 0; j < m; j++) {cin >> a[j];minv = min(minv, a[j]);}for (int j = 0; j < m; j++) {sum += a[j] - minv;}cout << sum << endl;}
}

B - Equal Candies CodeForces - 1676B相关推荐

  1. B. Equal Candies

    There are nnn boxes with different quantities of candies in each of them. The iii-th box has aia_iai ...

  2. Codeforces Round #572 (Div. 2)(ABCD1D2E)

    Keanu Reeves CodeForces - 1189A After playing Neo in the legendary "Matrix" trilogy, Keanu ...

  3. codeforces数学1600day4[贪心数学公式推导CodeForces - 1151D ,思维CodeForces - 1085C,数论同余+组合计数 CodeForces - 1056B]

    A - Stas and the Queue at the Buffet CodeForces - 1151D 题目大意:就是给你n个人在排队,每个人都有一个ai值和bi值,每个人的不满意度就是f(i ...

  4. Codeforces Round #640 (Div. 4)(ABCDE)

    Sum of Round Numbers CodeForces - 1352A 思路:按照题意模拟即可. 代码如下: #include<bits/stdc++.h> #define ll ...

  5. Make Product Equal One(思维)

    Make Product Equal One - CodeForces 1206B - Virtual Judge (csgrandeur.cn) 想复杂了,这题考的边界情况对我来说有点多,挺好的一题 ...

  6. 19级爪哇程序设计新手赛2.0(参考题解)

    看完它 A - Candies CodeForces - 1343A 题意: (1)玄学观察法,咋们先来看看案例: 3 --> 1 除以3==2^2-1 6 --> 2 除以3 7 --& ...

  7. CF思维联系– CodeForces - 991C Candies(二分)

    ACM思维题训练集合 After passing a test, Vasya got himself a box of n candies. He decided to eat an equal am ...

  8. Codeforces 1196A Three Piles of Candies

    https://codeforces.com/contest/1196/problem/A 题解: /* *@Author: STZG *@Language: C++ */ #include < ...

  9. Codeforces Round #552 (Div. 3) —— B. Make Them Equal

    B. Make Them Equal time limit per test2 seconds memory limit per test256 megabytes inputstandard inp ...

最新文章

  1. IC/FPGA 技术交流
  2. .net程序员的盲点(八):泛型
  3. Openwrt系统初始时间
  4. Django1.7如何配置静态资源访问
  5. go实现区块链[3]-遍历区块链与数据库持久化
  6. Java设计模式学习总结(14)——结构型模式之代理模式
  7. [工具类]DataTable与泛型集合List互转
  8. 使用EFS加密文件的共享
  9. Robotium 常用方法
  10. MIPS shellcode
  11. python正则表达式提取电话号码_用于提取电话号码的正则表达式
  12. SPJ数据库—初识sql语句(02)(注释版)
  13. iPhone 各大机型设备号
  14. CS0012 错误。必须添加对程序集”xxxxx,Version=4.0.0.0,Culture=neutral,PublicKeyToken=xxxxxxx“的引用
  15. HP ProBook 4421s配置完成无线网卡
  16. [渝粤教育] 郑州工程技术学院 大学计算机基础 参考 资料
  17. 做一个温暖如春的女子
  18. ant java /jre,关于java:Ant:找不到类:javac1.8
  19. dr.oracle素颜霜好用吗,什么牌子的素颜霜保湿效果好呢?好用的素颜霜让你的皮肤越来越好...
  20. ROS学习笔记(四)学会构建你的package

热门文章

  1. Friends 人物简介
  2. 5、(五)外汇学习基础篇之银行间外汇掉期交易
  3. 哈夫曼树以及哈夫曼算法
  4. 颜值|性价比均出色,一加Buds N耳机上手,它为何这么敢造?
  5. 5个开源的Java项目快速开发脚手架,项目经验有了
  6. 【redis】发布和订阅消息
  7. 生成tli tlh 文件
  8. 用户登录界面的测试用例分析
  9. Golang和Erlang消息传递机制对比
  10. 腾讯云弹性伸缩工程优化揭秘