CF1649B.Game of Ball Passing

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Daniel is watching a football team playing a game during their training session. They want to improve their passing skills during that session.

The game involves nn players, making multiple passes towards each other. Unfortunately, since the balls were moving too fast, after the session Daniel is unable to know how many balls were involved during the game. The only thing he knows is the number of passes delivered by each player during all the session.

Find the minimum possible amount of balls that were involved in the game.

丹尼尔正在观看一支足球队在训练课中的比赛。他们希望借此提升传球技巧。

该比赛涉及 nn 名球员,彼此之间进行了多次传球。不幸的是,由于球速过快,训练结束后丹尼尔无法确定比赛中总共使用了多少个球。他唯一知道的是:每名球员在整个训练过程中完成的传球次数。

请找出比赛中可能涉及的最少球数。

输入格式

There are several test cases in the input data. The first line contains a single integer tt (1≤t≤5⋅1041 \leq t \leq 5 \cdot 10^4) — the number of test cases. This is followed by the test cases description.

The first line of each test case contains one integer nn (2≤n≤1052 \leq n \leq 10^5) — the number of players.

The second line of the test case contains a sequence of integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1090 \leq a_i \leq 10^9), where aia_i is the number of passes delivered by the ii-th player.

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

输入数据包含多个测试用例。第一行包含一个整数 tt(1≤t≤5⋅1041 \leq t \leq 5 \cdot 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(2≤n≤1052 \leq n \leq 10^5),表示玩家数量。

每个测试用例的第二行包含一个整数序列 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤1090 \leq a_i \leq 10^9),其中 aia_i 表示第 ii 位玩家完成的传球次数。

保证所有测试用例的 nn 之和不超过 10510^5。

输出格式

For each test case print a single integer — the answer to the problem.

对于每个测试用例,输出一个整数——即该问题的答案。

输入输出样例

  • 输入#1

    4
    4
    2 3 3 2
    3
    1 5 2
    2
    0 0
    4
    1000000000 1000000000 1000000000 1000000000

    输出#1

    1
    2
    0
    1

说明/提示

In the first test case, with the only ball, the game can go like this:

2→1→3→4→1→2→3→4→2→3→22 \rightarrow 1 \rightarrow 3 \rightarrow 4 \rightarrow 1 \rightarrow 2 \rightarrow 3 \rightarrow 4 \rightarrow 2 \rightarrow 3 \rightarrow 2.

In the second test case, there is no possible way to play the game with only one ball. One possible way to play with two balls:

2→1→2→3→2→12 \rightarrow 1 \rightarrow 2 \rightarrow 3 \rightarrow 2 \rightarrow 1.

2→3→2→12 \rightarrow 3 \rightarrow 2 \rightarrow 1

In the third example, there were no passes, so 00 balls are possible.

在第一个测试用例中,仅有一个球时,游戏可能按如下方式进行:

2→1→3→4→1→2→3→4→2→3→22 \rightarrow 1 \rightarrow 3 \rightarrow 4 \rightarrow 1 \rightarrow 2 \rightarrow 3 \rightarrow 4 \rightarrow 2 \rightarrow 3 \rightarrow 2。

在第二个测试用例中,仅使用一个球无法进行游戏。使用两个球的一种可能方式进行如下:

2→1→2→3→2→12 \rightarrow 1 \rightarrow 2 \rightarrow 3 \rightarrow 2 \rightarrow 1。

2→3→2→12 \rightarrow 3 \rightarrow 2 \rightarrow 1

在第三个示例中,没有发生任何传球,因此可以使用 00 个球。

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

首页