CF1624A.Plus One on the Subset

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Polycarp got an array of integers a[1…n]a[1 \dots 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=⋯=ana_1=a_2=\dots=a_n).

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

For example, let a=[4,2,1,6,2]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 11. As a result, in one operation, he can get a new state of the array a=[5,3,1,7,2]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=⋯=ana_1=a_2=\dots=a_n)?

Polycarp 收到了一个整数数组 a[1…n]a[1 \dots n] 作为礼物。现在,他希望执行若干次(可能为零次)操作,使得数组中所有元素都相等(即满足 a1=a2=⋯=ana_1=a_2=\dots=a_n)。

  • 每次操作中,他可以选择数组中的若干下标,并将这些下标位置上的元素值增加 11。

例如,设 a=[4,2,1,6,2]a=[4,2,1,6,2]。他可以执行如下操作:选择下标 11、22 和 44,并将这些位置上的元素值各加 11。这样,一次操作后,数组变为 a=[5,3,1,7,2]a=[5,3,1,7,2]。

为使数组中所有元素相等(即满足 a1=a2=⋯=ana_1=a_2=\dots=a_n),所需的最少操作次数是多少?

输入格式

The first line of the input contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases in the test.

The following are descriptions of the input test cases.

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

The second line of the description of each test case contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1091 \le a_i \le 10^9) — elements of the array aa.

输入的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)——测试用例的数量。

接下来是各测试用例的输入描述。

每个测试用例描述的第一行包含一个整数 nn(1≤n≤501 \le n \le 50)——数组 aa 的长度。

每个测试用例描述的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1091 \le a_i \le 10^9)——数组 aa 的元素。

输出格式

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

对于每个测试用例,输出一个整数——使数组 aa 的所有元素相等所需的最少操作次数。

输入输出样例

  • 输入#1

    3
    6
    3 4 2 4 1 2
    3
    1000 1002 998
    2
    12 11

    输出#1

    3
    4
    1

说明/提示

First test case:

  • a=[3,4,2,4,1,2]a=[3,4,2,4,1,2] take a3,a5a_3, a_5 and perform an operation plus one on them, as a result we get a=[3,4,3,4,2,2]a=[3,4,3,4,2,2].
  • a=[3,4,3,4,2,2]a=[3,4,3,4,2,2] we take a1,a5,a6a_1, a_5, a_6 and perform an operation on them plus one, as a result we get a=[4,4,3,4,3,3]a=[4,4,3,4,3,3].
  • a=[4,4,3,4,3,3]a=[4,4,3,4,3,3] we take a3,a5,a6a_3, a_5, a_6 and perform an operation on them plus one, as a result we get a=[4,4,4,4,4,4]a=[4,4,4,4,4,4].

There are other sequences of 33 operations, after the application of which all elements become equal.

Second test case:

  • a=[1000,1002,998]a=[1000,1002,998] 2 times we take a1,a3a_1, a_3 and perform an operation plus one on them, as a result we get a=[1002,1002,1000]a=[1002,1002,1000].
  • a=[1002,1002,1000]a=[1002,1002,1000] also take a3a_3 2 times and perform an operation plus one on it, as a result we get a=[1002,1002,1002]a=[1002,1002,1002].

Third test case:

  • a=[12,11]a=[12,11] take a2a_2 and perform an operation plus one on it, as a result we get a=[12,12]a=[12,12].

第一个测试用例:

  • a=[3,4,2,4,1,2]a=[3,4,2,4,1,2],选取 a3,a5a_3, a_5 并对它们执行加一操作,结果得到 a=[3,4,3,4,2,2]a=[3,4,3,4,2,2]。
  • a=[3,4,3,4,2,2]a=[3,4,3,4,2,2],选取 a1,a5,a6a_1, a_5, a_6 并对它们执行加一操作,结果得到 a=[4,4,3,4,3,3]a=[4,4,3,4,3,3]。
  • a=[4,4,3,4,3,3]a=[4,4,3,4,3,3],选取 a3,a5,a6a_3, a_5, a_6 并对它们执行加一操作,结果得到 a=[4,4,4,4,4,4]a=[4,4,4,4,4,4]。

存在其他由 33 次操作组成的序列,使得所有元素在操作后均相等。

第二个测试用例:

  • a=[1000,1002,998]a=[1000,1002,998],选取 a1,a3a_1, a_3 并对其执行两次加一操作,结果得到 a=[1002,1002,1000]a=[1002,1002,1000]。
  • a=[1002,1002,1000]a=[1002,1002,1000],再对 a3a_3 执行两次加一操作,结果得到 a=[1002,1002,1002]a=[1002,1002,1002]。

第三个测试用例:

  • a=[12,11]a=[12,11],选取 a2a_2 并对其执行一次加一操作,结果得到 a=[12,12]a=[12,12]。

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

首页