CF1792A.GamingForces

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Monocarp is playing a computer game. He's going to kill nn monsters, the ii-th of them has hih_i health.

Monocarp's character has two spells, either of which he can cast an arbitrary number of times (possibly, zero) and in an arbitrary order:

  • choose exactly two alive monsters and decrease their health by 11;
  • choose a single monster and kill it.

When a monster's health becomes 00, it dies.

What's the minimum number of spell casts Monocarp should perform in order to kill all monsters?

Monocarp 正在玩一款电脑游戏。他需要杀死 nn 只怪物,其中第 ii 只怪物的生命值为 hih_i。

Monocarp 的角色拥有两种法术,他可以以任意顺序、任意次数(包括零次)施放这两种法术:

  • 选择恰好两只仍然存活的怪物,并将它们的生命值各减少 11;
  • 选择一只怪物并直接将其杀死。

当一只怪物的生命值变为 00 时,它即死亡。

Monocarp 至少需要施放多少次法术,才能杀死所有怪物?

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of testcases.

The first line of each testcase contains a single integer nn (1≤n≤1001 \le n \le 100) — the number of monsters.

The second line contains nn integers h1,h2,…,hnh_1, h_2, \dots, h_n (1≤hi≤1001 \le h_i \le 100) — the health of each monster.

The sum of nn over all testcases doesn't exceed 2⋅1042 \cdot 10^4.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)——测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤1001 \le n \le 100)——怪物的数量。

第二行包含 nn 个整数 h1,h2,…,hnh_1, h_2, \dots, h_n(1≤hi≤1001 \le h_i \le 100)——每个怪物的生命值。

所有测试用例中 nn 的总和不超过 2⋅1042 \cdot 10^4。

输出格式

For each testcase, print a single integer — the minimum number of spell casts Monocarp should perform in order to kill all monsters.

对于每个测试用例,输出一个整数——Monocarp 为消灭所有怪物所需的最少施法次数。

输入输出样例

  • 输入#1

    3
    4
    1 2 1 2
    3
    2 4 2
    5
    1 2 3 4 5

    输出#1

    3
    3
    5

说明/提示

In the first testcase, the initial health list is [1,2,1,2][1, 2, 1, 2]. Three spells are casted:

  • the first spell on monsters 11 and 22 — monster 11 dies, monster 22 has now health 11, new health list is [0,1,1,2][0, 1, 1, 2];
  • the first spell on monsters 33 and 44 — monster 33 dies, monster 44 has now health 11, new health list is [0,1,0,1][0, 1, 0, 1];
  • the first spell on monsters 22 and 44 — both monsters 22 and 44 die.

In the second testcase, the initial health list is [2,4,2][2, 4, 2]. Three spells are casted:

  • the first spell on monsters 11 and 33 — both monsters have health 11 now, new health list is [1,4,1][1, 4, 1];
  • the second spell on monster 22 — monster 22 dies, new health list is [1,0,1][1, 0, 1];
  • the first spell on monsters 11 and 33 — both monsters 11 and 33 die.

In the third testcase, the initial health list is [1,2,3,4,5][1, 2, 3, 4, 5]. Five spells are casted. The ii-th of them kills the ii-th monster with the second spell. Health list sequence: [1,2,3,4,5][1, 2, 3, 4, 5] →\rightarrow [0,2,3,4,5][0, 2, 3, 4, 5] →\rightarrow [0,0,3,4,5][0, 0, 3, 4, 5] →\rightarrow [0,0,0,4,5][0, 0, 0, 4, 5] →\rightarrow [0,0,0,0,5][0, 0, 0, 0, 5] →\rightarrow [0,0,0,0,0][0, 0, 0, 0, 0].

在第一个测试用例中,初始生命值列表为 [1,2,1,2][1, 2, 1, 2]。共施放了三次法术:

  • 第一个法术作用于怪物 11 和 22 —— 怪物 11 死亡,怪物 22 当前生命值变为 11,新的生命值列表为 [0,1,1,2][0, 1, 1, 2];
  • 第一个法术作用于怪物 33 和 44 —— 怪物 33 死亡,怪物 44 当前生命值变为 11,新的生命值列表为 [0,1,0,1][0, 1, 0, 1];
  • 第一个法术作用于怪物 22 和 44 —— 怪物 22 和 44 均死亡。

在第二个测试用例中,初始生命值列表为 [2,4,2][2, 4, 2]。共施放了三次法术:

  • 第一个法术作用于怪物 11 和 33 —— 两个怪物当前生命值均变为 11,新的生命值列表为 [1,4,1][1, 4, 1];
  • 第二个法术作用于怪物 22 —— 怪物 22 死亡,新的生命值列表为 [1,0,1][1, 0, 1];
  • 第一个法术作用于怪物 11 和 33 —— 怪物 11 和 33 均死亡。

在第三个测试用例中,初始生命值列表为 [1,2,3,4,5][1, 2, 3, 4, 5]。共施放了五次法术。其中第 ii 次法术使用第二个法术击杀第 ii 个怪物。生命值列表变化过程为:
[1,2,3,4,5][1, 2, 3, 4, 5] →\rightarrow [0,2,3,4,5][0, 2, 3, 4, 5] →\rightarrow [0,0,3,4,5][0, 0, 3, 4, 5] →\rightarrow [0,0,0,4,5][0, 0, 0, 4, 5] →\rightarrow [0,0,0,0,5][0, 0, 0, 0, 5] →\rightarrow [0,0,0,0,0][0, 0, 0, 0, 0]。

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

首页