CF1891C Smilo and Monsters

题目描述

在 Smilo 的游戏中,有 $n$ 群怪兽,第 $i$ 群怪兽的数量为 $a_i$。游戏的目标是消灭所有的怪兽,有两种攻击方式: - 普攻:任选一群怪兽,击杀其中的一只,并让连击点数 $x$ 增加 $1$。 - 大招:选择一群数量不小于 $x$($x$ 是目前的连击点数)的怪兽,击杀其中的 $x$ 只,并让连击点数归零。 一次普攻或一次大招记作一次攻击。初始连击点数为 $0$,请求出消灭所有怪兽的最少攻击次数。

输入格式

**本题有多组输入数据**。第一行一个整数 $T$($1 \leq T \leq 10^4$),表示数据组数。 对于每组数据,第一行一个整数 $n$($1 \leq n \leq 2 \times 10^5$),表示怪兽群数;第二行 $n$ 个整数 $a_i$($1 \leq a_i \leq 10^9$),表示每群怪兽的数量。 保证单个测试点中所有数据的 $n$ 总和不超过 $2 \times 10^5$。

输出格式

对于每组数据,输出消灭所有怪兽需要的最少攻击次数,一行一个答案。 #### 样例解释 - 第一组数据:对第 $1$ 群、第 $3$ 群、第 $4$ 群怪兽各使用一次普攻,对第 $2$ 群怪兽使用一次大招。 - 第二组数据:对第 $1$ 群、第 $3$ 群怪兽各使用一次普攻,对第 $2$ 群怪兽使用一次大招,再对第 $4$ 群怪兽使用一次普攻。 - 第四组数据:对第 $1$ 群使用 $1$ 次普攻,对第 $2$ 群使用 $2$ 次普攻,再对第 $2$ 群使用一次大招,最后对第 $2$ 群再使用一次普攻。

说明/提示

In the first test case, we can use an attack of the first type on the $ 1 $ -st, $ 3 $ -rd and $ 4 $ -th hordes, and then use an attack of the second type to finish off the $ 2 $ -nd horde. We need $ 4 $ attacks in total. In the second test case, we can use an attack of the first type on the $ 1 $ -st and $ 3 $ -rd hordes, then use an attack of the second type to finish off the $ 2 $ -nd horde, and then use an attack of the first type on the $ 4 $ -th horde. We need $ 4 $ attacks in total. In the fourth test case, we can use an attack of the first type once on the $ 1 $ -st horde, twice on the $ 2 $ -nd horde, and then use an attack of the second type on the $ 2 $ -nd horde, and finally use an attack of the first type to finish off the $ 2 $ -nd horde. We need $ 5 $ attacks in total.