CF1615A.Closing The Gap

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are nn block towers in a row, where tower ii has a height of aia_i . 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 ii and jj ( 1i,jn1 \leq i, j \leq n ; iji \neq j ), and move a block from tower ii to tower jj . This essentially decreases aia_i by 11 and increases aja_j by 11 .

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)\max(a)-\min(a) .

What's the minimum possible ugliness you can achieve, after any number of days?

输入格式

The first line contains one integer tt ( 1t10001 \leq t \leq 1000 ) — the number of test cases. Then tt cases follow.

The first line of each test case contains one integer nn ( 2n1002 \leq n \leq 100 ) — the number of buildings.

The second line of each test case contains nn space separated integers a1,a2,,ana_1, a_2, \ldots, a_n ( 1ai1071 \leq a_i \leq 10^7 ) — 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 00 .

In the second test case, you should do one operation, with i=1i = 1 and j=3j = 3 . The new heights will now be [2,2,2,2][2, 2, 2, 2] , with an ugliness of 00 .

In the third test case, you may do three operations:

  1. with i=3i = 3 and j=1j = 1 . The new array will now be [2,2,2,1,5][2, 2, 2, 1, 5] ,
  2. with i=5i = 5 and j=4j = 4 . The new array will now be [2,2,2,2,4][2, 2, 2, 2, 4] ,
  3. with i=5i = 5 and j=3j = 3 . The new array will now be [2,2,3,2,3][2, 2, 3, 2, 3] .

The resulting ugliness is 11 . It can be proven that this is the minimum possible ugliness for this test.

首页