Plus One on the Subset

https://acs.jxnu.edu.cn/problem/CF1624A

描述:

Polycarp got an array of integers a[1…n]a[1…n] as a gift. Now he wants to perform a certain number of operations (possibly zero) so that all elements of the array become the same (that is, to become a1=a2=⋯=ana1=a2=⋯=an).

P得到了一个整数数组作为礼物。现在他想执行一些操作来使数组中的元素变得相同。

  • In one operation, he can take some indices in the array and increase the elements of the array at those indices by 1.

在一此操作中他能够得到一些数组里的索引并且让这个元素加1.

For example, let a=[4,2,1,6,2] He can perform the following operation: select indices 1, 2, and 4 and increase elements of the array in those indices by 1. As a result, in one operation, he can get a new state of the array a=[5,3,1,7,2]

例如,让a=【4 2 1 6 2】,他能执行下面的操作。选择1,2,4号元素并且让这些元素增长1.结果是,在这个操作后,他能得到新状态的数组a=[5,3,1,7,2]

What is the minimum number of operations it can take so that all elements of the array become equal to each other (that is, to become a1=a2=⋯=ana1=a2=⋯=an)?

能让所有元素互相相等的最小操作数是多少

输入:

The first line of the input contains a single integer t (1≤t≤1041≤t≤104)  — the number of test cases in the test.

第一行输入包含一个整数t  测试样例的数量。

The following are descriptions of the input test cases.

后面的是描述输入样例。

The first line of the description of each test case contains one integer n (1≤n≤501≤n≤50)  — the array a.

第一行描述每一个测试样例包含一个整数n  数组a元素个数

The second line of the description of each test case contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109)  — elements of the array aa.

第二行描述每一个测试样例,包含n个整数a1,a2.....an。a数组的元素

输出:

For each test case, print one integer  — the minimum number of operations to make all elements of the array aa equal.

对于每个测试样例,输出一个整数 让数组所有元素相等的最小操作数。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值