CF1615A.Closing The Gap
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n block towers in a row, where tower i has a height of ai . You're part of a building crew, and you want to make the buildings look as nice as possible. In a single day, you can perform the following operation:
- Choose two indices i and j ( 1≤i,j≤n ; i=j ), and move a block from tower i to tower j . This essentially decreases ai by 1 and increases aj by 1 .
You think the ugliness of the buildings is the height difference between the tallest and shortest buildings. Formally, the ugliness is defined as max(a)−min(a) .
What's the minimum possible ugliness you can achieve, after any number of days?
输入格式
The first line contains one integer t ( 1≤t≤1000 ) — the number of test cases. Then t cases follow.
The first line of each test case contains one integer n ( 2≤n≤100 ) — the number of buildings.
The second line of each test case contains n space separated integers a1,a2,…,an ( 1≤ai≤107 ) — the heights of the buildings.
输出格式
For each test case, output a single integer — the minimum possible ugliness of the buildings.
输入输出样例
输入#1
3 3 10 10 10 4 3 2 1 2 5 1 2 3 1 5
输出#1
0 0 1
说明/提示
In the first test case, the ugliness is already 0 .
In the second test case, you should do one operation, with i=1 and j=3 . The new heights will now be [2,2,2,2] , with an ugliness of 0 .
In the third test case, you may do three operations:
- with i=3 and j=1 . The new array will now be [2,2,2,1,5] ,
- with i=5 and j=4 . The new array will now be [2,2,2,2,4] ,
- with i=5 and j=3 . The new array will now be [2,2,3,2,3] .
The resulting ugliness is 1 . It can be proven that this is the minimum possible ugliness for this test.