CF1537A.Arithmetic Array
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 fracb_1+cdots+b_kk 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.
输入格式
The first line contains a single integer t ( 1≤t≤1000 ) — the number of test cases. Then t test cases follow.
The first line of each test case contains a single integer n ( 1≤n≤50 ) — the length of the initial array a .
The second line of each test case contains n integers a1,…,an ( −104≤ai≤104 ), the elements of the array.
输出格式
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 .
输入输出样例
输入#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 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 2−2+4 which is equal to 1 .