题库练习 Smilo and Monsters
← 上一题 下一题 →

A16346 | Smilo and Monsters

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

A boy called Smilo is playing a new game! In the game, there are $n$ hordes of monsters, and the $i$ -th horde contains $a_i$ monsters. The goal of the game is to destroy all the monsters. To do this, you have two types of attacks and a combo counter $x$ , initially set to $0$ :

- The first type: you choose a number $i$ from $1$ to $n$ , such that there is at least one monster left in the horde with the number $i$ . Then, you kill one monster from horde number $i$ , and the combo counter $x$ increases by $1$ .
- The second type: you choose a number $i$ from $1$ to $n$ , such that there are at least $x$ monsters left in the horde with number $i$ . Then, you use an ultimate attack and kill $x$ monsters from the horde with number $i$ . After that, $x$ is reset to zero.

Your task is to destroy all of the monsters, meaning that there should be no monsters left in any of the hordes. Smilo wants to win as quickly as possible, so he wants to the minimum number of attacks required to win the game.

输入格式

The first line contains a single integer $t$ ( $1 \leq t \leq 10^4$ ) — the number of test cases. The descriptions of the test cases follow.

The first line of each input data set contains a single integer $n$ ( $1 \leq n \leq 2 \cdot 10^5$ ) — the number of hordes of monsters.

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $1 \leq a_i \leq 10^9$ ) — the number of monsters in each horde.

It is guaranteed that the sum of $n$ across all test cases does not exceed $2 \cdot {10^5}$ .

输出格式

For each test case, out put the minimum number of attacks required to kill all monsters.

输入输出样例

输入 #1
4
4
1 3 1 1
4
1 2 1 1
6
3 2 1 5 2 4
2
1 6
输出 #1
4
4
11
5
C++ 编辑器
输入
输出