CF1537A.Arithmetic Array

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

An array bb of length kk is called good if its arithmetic mean is equal to 11. More formally, if $$\frac{b_1 + \cdots + b_k}{k}=1.$$

Note that the value b1+⋯+bkk\frac{b_1+\cdots+b_k}{k} is not rounded up or down. For example, the array [1,1,1,2][1,1,1,2] has an arithmetic mean of 1.251.25, which is not equal to 11.

You are given an integer array aa of length nn. In an operation, you can append a non-negative integer to the end of the array. What's the minimum number of operations required to make the array good?

We have a proof that it is always possible with finitely many operations.

长度为 kk 的数组 bb 被称为好数组,当且仅当它的算术平均值等于 11。更准确地说,满足

b1+⋯+bkk=1.\frac{b_1 + \cdots + b_k}{k}=1.

注意:值 b1+⋯+bkk\frac{b_1+\cdots+b_k}{k} 不进行向上或向下取整。例如,数组 [1,1,1,2][1,1,1,2] 的算术平均值为 1.251.25,不等于 11。

给定一个长度为 nn 的整数数组 aa。每次操作中,你可以在数组末尾追加一个非负整数。问:使该数组变为好数组所需的最少操作次数是多少?

我们已证明:总存在有限次操作可达成目标。

输入格式

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

The first line of each test case contains a single integer nn (1≤n≤501 \leq n \leq 50) — the length of the initial array aa.

The second line of each test case contains nn integers a1,…,ana_1,\ldots,a_n (−104≤ai≤104-10^4\leq a_i \leq 10^4), the elements of the array.

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

每个测试用例的第一行包含一个整数 nn(1≤n≤501 \leq n \leq 50),表示初始数组 aa 的长度。

每个测试用例的第二行包含 nn 个整数 a1,…,ana_1,\ldots,a_n(−104≤ai≤104-10^4\leq a_i \leq 10^4),即数组的元素。

输出格式

For each test case, output a single integer — the minimum number of non-negative integers you have to append to the array so that the arithmetic mean of the array will be exactly 11.

对于每个测试用例,输出一个整数——你需要附加到数组中的非负整数的最小个数,使得数组的算术平均值恰好为 11。

输入输出样例

  • 输入#1

    4
    3
    1 1 1
    2
    1 2
    4
    8 4 6 2
    1
    -2

    输出#1

    0
    1
    16
    1

说明/提示

In the first test case, we don't need to add any element because the arithmetic mean of the array is already 11, so the answer is 00.

In the second test case, the arithmetic mean is not 11 initially so we need to add at least one more number. If we add 00 then the arithmetic mean of the whole array becomes 11, so the answer is 11.

In the third test case, the minimum number of elements that need to be added is 1616 since only non-negative integers can be added.

In the fourth test case, we can add a single integer 44. The arithmetic mean becomes −2+42\frac{-2+4}{2} which is equal to 11.

在第一个测试用例中,我们无需添加任何元素,因为数组的算术平均值已经是 11,因此答案为 00。

在第二个测试用例中,初始时算术平均值不等于 11,因此我们需要至少再添加一个数。若添加 00,则整个数组的算术平均值变为 11,因此答案为 11。

在第三个测试用例中,需要添加的最少元素个数为 1616,因为只允许添加非负整数。

在第四个测试用例中,我们可以添加一个整数 44。此时算术平均值变为 −2+42\frac{-2+4}{2},其值等于 11。

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

首页