CF1615A.Closing The Gap

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

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 (1≤i,j≤n1 \leq i, j \leq n; i≠ji \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?

一行中有 nn 座积木塔,其中第 ii 座塔的高度为 aia_i。你是一名建筑队的成员,希望让这些建筑看起来尽可能美观。在一天内,你可以执行以下操作:

  • 选择两个下标 ii 和 jj(满足 1≤i,j≤n1 \leq i, j \leq n 且 i≠ji \neq j),并将一个积木块从第 ii 座塔移动到第 jj 座塔。该操作实质上使 aia_i 减少 11,同时使 aja_j 增加 11。

你认为建筑的“丑陋度”等于最高塔与最矮塔之间的高度差。形式化地,丑陋度定义为 max⁡(a)−min⁡(a)\max(a)-\min(a)。

在经过任意天数的操作后,你能达到的最小可能丑陋度是多少?

输入格式

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

The first line of each test case contains one integer nn (2≤n≤1002 \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 (1≤ai≤1071 \leq a_i \leq 10^7) — the heights of the buildings.

第一行包含一个整数 tt(1≤t≤10001 \leq t \leq 1000),表示测试用例的数量。随后是 tt 个测试用例。

每个测试用例的第一行包含一个整数 nn(2≤n≤1002 \leq n \leq 100),表示建筑物的数量。

每个测试用例的第二行包含 nn 个以空格分隔的整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1071 \leq a_i \leq 10^7),表示各建筑物的高度。

输出格式

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.

在第一个测试用例中,丑陋度已经是 00。

在第二个测试用例中,你需要执行一次操作,其中 i=1i = 1 且 j=3j = 3。新的高度数组将变为 [2,2,2,2][2, 2, 2, 2],丑陋度为 00。

在第三个测试用例中,你可以执行三次操作:

  1. 取 i=3i = 3 且 j=1j = 1,新数组变为 [2,2,2,1,5][2, 2, 2, 1, 5];
  2. 取 i=5i = 5 且 j=4j = 4,新数组变为 [2,2,2,2,4][2, 2, 2, 2, 4];
  3. 取 i=5i = 5 且 j=3j = 3,新数组变为 [2,2,3,2,3][2, 2, 3, 2, 3]。

最终的丑陋度为 11。可以证明,这是该测试用例所能达到的最小丑陋度。

输入解题思路,AI测评打分。不知道怎么写?

首页