CF1891C.Smilo and Monsters

普及/提高-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

A boy called Smilo is playing a new game! In the game, there are nn hordes of monsters, and the ii-th horde contains aia_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 xx, initially set to 00:

  • The first type: you choose a number ii from 11 to nn, such that there is at least one monster left in the horde with the number ii. Then, you kill one monster from horde number ii, and the combo counter xx increases by 11.
  • The second type: you choose a number ii from 11 to nn, such that there are at least xx monsters left in the horde with number ii. Then, you use an ultimate attack and kill xx monsters from the horde with number ii. After that, xx 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.

一个名叫斯米洛的男孩正在玩一款新游戏!游戏中有 nn 群怪物,其中第 ii 群包含 aia_i 只怪物。游戏的目标是消灭所有怪物。为此,你有两种攻击方式以及一个连击计数器 xx(初始值为 00):

  • 第一种攻击:选择一个编号 ii(1≤i≤n1 \le i \le n),要求第 ii 群中至少还剩一只怪物;然后你消灭第 ii 群中的一只怪物,同时连击计数器 xx 增加 11。
  • 第二种攻击:选择一个编号 ii(1≤i≤n1 \le i \le n),要求第 ii 群中至少还剩 xx 只怪物;然后你发动终极攻击,消灭第 ii 群中的 xx 只怪物;之后,xx 被重置为 00。

你的任务是消灭所有怪物,即所有群中都不再剩下任何怪物。斯米洛希望尽快获胜,因此他想知道赢得游戏所需的最少攻击次数。

输入格式

The first line contains a single integer tt (1≤t≤1041 \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 nn (1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5) — the number of hordes of monsters.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1091 \leq a_i \leq 10^9) — the number of monsters in each horde.

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

第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4)——测试用例的数量。随后是各测试用例的描述。

每个输入数据集的第一行包含一个整数 nn(1≤n≤2⋅1051 \leq n \leq 2 \cdot 10^5)——怪物群的数量。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤1091 \leq a_i \leq 10^9)——每群怪物的数量。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \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

说明/提示

In the first test case, we can use an attack of the first type on the 11-st, 33-rd and 44-th hordes, and then use an attack of the second type to finish off the 22-nd horde. We need 44 attacks in total.

In the second test case, we can use an attack of the first type on the 11-st and 33-rd hordes, then use an attack of the second type to finish off the 22-nd horde, and then use an attack of the first type on the 44-th horde. We need 44 attacks in total.

In the fourth test case, we can use an attack of the first type once on the 11-st horde, twice on the 22-nd horde, and then use an attack of the second type on the 22-nd horde, and finally use an attack of the first type to finish off the 22-nd horde. We need 55 attacks in total.

在第一个测试用例中,我们可以对第 11、第 33 和第 44 波敌军各使用一次第一类攻击,然后对第 22 波敌军使用一次第二类攻击将其消灭。总共需要 44 次攻击。

在第二个测试用例中,我们可以对第 11 和第 33 波敌军各使用一次第一类攻击,然后对第 22 波敌军使用一次第二类攻击将其消灭,最后对第 44 波敌军使用一次第一类攻击。总共需要 44 次攻击。

在第四个测试用例中,我们可以对第 11 波敌军使用一次第一类攻击,对第 22 波敌军使用两次第一类攻击,然后对第 22 波敌军使用一次第二类攻击,最后再对第 22 波敌军使用一次第一类攻击将其消灭。总共需要 55 次攻击。

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

首页