欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1784A.Monsters (easy version)
Monsters (easy version)
This is the easy version of the problem. In this version, you only need to find the answer once. In this version, hacks are not allowed.
In a computer game, you are fighting against monsters. Monster number has health points, all are integers. A monster is alive while it has at least health point.
You can cast spells of two types:
- Deal damage to any single alive monster of your choice.
- Deal damage to all alive monsters. If at least one monster dies (ends up with health points) as a result of this action, then repeat it (and keep repeating while at least one monster dies every time).
Dealing damage to a monster reduces its health by .
Spells of type 1 can be cast any number of times, while a spell of type 2 can be cast at most once during the game.
What is the smallest number of times you need to cast spells of type 1 to kill all monsters?
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
Each test case consists of two lines. The first line contains a single integer () — the number of monsters.
The second line contains integers () — monsters' health points.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, print a single integer — the smallest number of times you need to cast spells of type 1 to kill all monsters.
Note
In the first test case, the initial health points of the monsters are . It is enough to cast a spell of type 2:
- Monsters' health points change to . Since monster number dies, the spell is repeated.
- Monsters' health points change to . Since monster number dies, the spell is repeated.
- Monsters' health points change to . Since monster number dies, the spell is repeated.
- Monsters' health points change to .
Since it is possible to use no spells of type 1 at all, the answer is .
In the second test case, the initial health points of the monsters are . Here is one of the optimal action sequences:
- Using a spell of type 1, deal damage to monster number . Monsters' health points change to .
- Using a spell of type 1, deal damage to monster number . Monsters' health points change to .
- Using a spell of type 1, deal damage to monster number again. Monsters' health points change to .
- Use a spell of type 2:
- Monsters' health points change to . Since monsters number , , and die, the spell is repeated.
- Monsters' health points change to . Since monster number dies, the spell is repeated.
- Monsters' health points change to . Since monster number dies, the spell is repeated.
- Monsters' health points change to .
- Using a spell of type 1, deal damage to monster number . Monsters' health points change to .
Spells of type 1 are cast times in total. It can be shown that this is the smallest possible number.
Samples
2
3
3 1 2
6
4 1 5 4 1 1
0
4
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |