309979: CF1767B. Block Towers

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Block Towers

题意翻译

给定一个 $n$ 个数的数列 $a_1,a_2,\dots ,a_n$。 在每次操作中,你可以选定两个位置 $i,j$ 且满足 $a_i>a_j$,把 $a_i$ 减去 $1$,同时把 $a_j$ 加上 $1$。 询问在任意多次操作后,$a_1$ 的最大值是多少?

题目描述

There are $ n $ block towers, numbered from $ 1 $ to $ n $ . The $ i $ -th tower consists of $ a_i $ blocks. In one move, you can move one block from tower $ i $ to tower $ j $ , but only if $ a_i > a_j $ . That move increases $ a_j $ by $ 1 $ and decreases $ a_i $ by $ 1 $ . You can perform as many moves as you would like (possibly, zero). What's the largest amount of blocks you can have on the tower $ 1 $ after the moves?

输入输出格式

输入格式


The first line contains a single integer $ t $ ( $ 1 \le t \le 10^4 $ ) — the number of testcases. The first line of each testcase contains a single integer $ n $ ( $ 2 \le n \le 2 \cdot 10^5 $ ) — the number of towers. The second line contains $ n $ integers $ a_1, a_2, \dots, a_n $ ( $ 1 \le a_i \le 10^9 $ ) — the number of blocks on each tower. The sum of $ n $ over all testcases doesn't exceed $ 2 \cdot 10^5 $ .

输出格式


For each testcase, print the largest amount of blocks you can have on the tower $ 1 $ after you make any number of moves (possibly, zero).

输入输出样例

输入样例 #1

4
3
1 2 3
3
1 2 2
2
1 1000000000
10
3 8 6 7 4 1 2 4 10 1

输出样例 #1

3
2
500000001
9

说明

In the first testcase, you can move a block from tower $ 2 $ to tower $ 1 $ , making the block counts $ [2, 1, 3] $ . Then move a block from tower $ 3 $ to tower $ 1 $ , making the block counts $ [3, 1, 2] $ . Tower $ 1 $ has $ 3 $ blocks in it, and you can't obtain a larger amount. In the second testcase, you can move a block from any of towers $ 2 $ or $ 3 $ to tower $ 1 $ , so that it has $ 2 $ blocks in it. In the third testcase, you can $ 500000000 $ times move a block from tower $ 2 $ to tower $ 1 $ . After that the block countes will be $ [500000001, 500000000] $ .

Input

题意翻译

给定一个 $n$ 个数的数列 $a_1,a_2,\dots ,a_n$。 在每次操作中,你可以选定两个位置 $i,j$ 且满足 $a_i>a_j$,把 $a_i$ 减去 $1$,同时把 $a_j$ 加上 $1$。 询问在任意多次操作后,$a_1$ 的最大值是多少?

Output

**块塔**

**题意翻译**
给定一个包含 $n$ 个数的数列 $a_1, a_2, \dots, a_n$。

在每次操作中,你可以选择两个位置 $i, j$ 并满足 $a_i > a_j$,然后将 $a_i$ 减去 1,同时将 $a_j$ 加上 1。

询问在任意多次操作后,$a_1$ 的最大值是多少?

**题目描述**
有 $n$ 个块塔,编号从 1 到 $n$。第 $i$ 个塔由 $a_i$ 个块组成。

在一次移动中,你可以将一个块从塔 $i$ 移动到塔 $j$,但只有当 $a_i > a_j$ 时才能这样做。这个移动会使 $a_j$ 增加 1,$a_i$ 减少 1。你可以执行任意多次移动(可能为零)。

在移动之后,你可以在塔 $1$ 上拥有多少块的最大数量?

**输入输出格式**
**输入格式**
第一行包含一个整数 $t$($1 \le t \le 10^4$)——测试用例的数量。

每个测试用例的第一行包含一个整数 $n$($2 \le n \le 2 \cdot 10^5$)——塔的数量。

第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$($1 \le a_i \le 10^9$)——每座塔上的块数。

所有测试用例的 $n$ 之和不超过 $2 \cdot 10^5$。

**输出格式**
对于每个测试用例,输出在你可以进行任意次数移动(可能为零)后,塔 $1$ 上可以拥有的块的最大数量。

**输入输出样例**
**输入样例 #1**
```
4
3
1 2 3
3
1 2 2
2
1 1000000000
10
3 8 6 7 4 1 2 4 10 1
```
**输出样例 #1**
```
3
2
500000001
9
```

**说明**
在第一个测试用例中,你可以从塔 $2$ 移动一个块到塔 $1$,使得块数为 $[2, 1, 3]$。然后从塔 $3$ 移动一个块到塔 $1$,使得块数为 $[3, 1, 2]$。塔 $1$ 有 $3$ 个块,你不能得到更多的块。

在第二个测试用例中,你可以从塔 $2$ 或塔 $3$ 移动一个块到塔 $1$,使其拥有 $2$ 个块。

在第三个测试用例中,你可以 $500000000$ 次从塔 $2$ 移动一个块到塔 $1$。之后块数将为 $[500000001, 500000000]$。**块塔** **题意翻译** 给定一个包含 $n$ 个数的数列 $a_1, a_2, \dots, a_n$。 在每次操作中,你可以选择两个位置 $i, j$ 并满足 $a_i > a_j$,然后将 $a_i$ 减去 1,同时将 $a_j$ 加上 1。 询问在任意多次操作后,$a_1$ 的最大值是多少? **题目描述** 有 $n$ 个块塔,编号从 1 到 $n$。第 $i$ 个塔由 $a_i$ 个块组成。 在一次移动中,你可以将一个块从塔 $i$ 移动到塔 $j$,但只有当 $a_i > a_j$ 时才能这样做。这个移动会使 $a_j$ 增加 1,$a_i$ 减少 1。你可以执行任意多次移动(可能为零)。 在移动之后,你可以在塔 $1$ 上拥有多少块的最大数量? **输入输出格式** **输入格式** 第一行包含一个整数 $t$($1 \le t \le 10^4$)——测试用例的数量。 每个测试用例的第一行包含一个整数 $n$($2 \le n \le 2 \cdot 10^5$)——塔的数量。 第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$($1 \le a_i \le 10^9$)——每座塔上的块数。 所有测试用例的 $n$ 之和不超过 $2 \cdot 10^5$。 **输出格式** 对于每个测试用例,输出在你可以进行任意次数移动(可能为零)后,塔 $1$ 上可以拥有的块的最大数量。 **输入输出样例** **输入样例 #1** ``` 4 3 1 2 3 3 1 2 2 2 1 1000000000 10 3 8 6 7 4 1 2 4 10 1 ``` **输出样例 #1** ``` 3 2 500000001 9 ``` **说明** 在第一个测试用例中,你可以从塔 $2$ 移动一个块到塔 $1$,使得块数为 $[2, 1, 3]$。然后从塔 $3$ 移动一个块到塔 $1$,使得块数为 $[3, 1, 2]$。塔 $1$ 有 $3$ 个块,你不能得到更多的块。 在第二个测试用例中,你可以从塔 $2$ 或塔 $3$ 移动一个块到塔 $1$,使其拥有 $2$ 个块。 在第三个测试用例中,你可以 $500000000$ 次从塔 $2$ 移动一个块到塔 $1$。之后块数将为 $[500000001, 500000000]$。

加入题单

算法标签: