CF1452B.Toy Blocks

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are asked to watch your nephew who likes to play with toy blocks in a strange way.

He has nn boxes and the ii -th box has aia_i blocks. His game consists of two steps:

  1. he chooses an arbitrary box ii ;
  2. he tries to move all blocks from the ii -th box to other boxes.

If he can make the same number of blocks in each of n1n - 1 other boxes then he will be happy, otherwise, will be sad. Note that your nephew can only move the blocks from the chosen box to the other boxes; he cannot move blocks from the other boxes.You don't want to make your nephew sad, so you decided to put several extra blocks into some boxes in such a way that no matter which box ii he chooses he won't be sad. What is the minimum number of extra blocks you need to put?

输入格式

The first line contains a single integer tt ( 1t10001 \le t \le 1000 ) — the number of test cases.

The first line of each test case contains the integer nn ( 2n1052 \le n \le 10^5 ) — the number of boxes.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \dots, a_n ( 0ai1090 \le a_i \le 10^9 ) — the number of blocks in each box.

It's guaranteed that the sum of nn over test cases doesn't exceed 10510^5 .

输出格式

For each test case, print a single integer — the minimum number of blocks you need to put. It can be proved that the answer always exists, i. e. the number of blocks is finite.

输入输出样例

  • 输入#1

    3
    3
    3 2 2
    4
    2 2 3 2
    3
    0 3 0

    输出#1

    1
    0
    3

说明/提示

In the first test case, you can, for example, put one extra block into the first box and make a=[4,2,2]a = [4, 2, 2] . If your nephew chooses the box with 44 blocks, then we will move two blocks to the second box and two blocks to the third box. If he chooses the box with 22 blocks then he will move these two blocks to the other box with 22 blocks.

In the second test case, you don't need to put any extra blocks, since no matter which box your nephew chooses, he can always make other boxes equal.

In the third test case, you should put 33 extra blocks. For example, you can put 22 blocks in the first box and 11 block in the third box. You'll get array a=[2,3,1]a = [2, 3, 1] .

首页