Codeforces Round 726 (Div. 2)
A
Arithmetic Array
Codeforces
800
原题
←B →
翻译中…

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

翻译中…

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

翻译中…

You are given an integer array $a$ of length $n$. 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.

翻译中…

Input

翻译中…

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

翻译中…

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

翻译中…

The second line of each test case contains $n$ integers $a_1,\ldots,a_n$ ($-10^4\leq a_i \leq 10^4$), the elements of the array.

翻译中…

Output

翻译中…

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 $1$.

翻译中…

Note

翻译中…

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

翻译中…

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

翻译中…

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

翻译中…

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

翻译中…

样例

Input #1
4
3
1 1 1
2
1 2
4
8 4 6 2
1
-2
Output #1
0
1
16
1
InputCopy OutputCopy
题目信息
题号
1537A
时间限制
1 s
内存限制
256 MB
标签
贪心
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。