QOJ.ac

QOJ

実行時間制限: 1.0 s メモリ制限: 256 MB 満点: 100 ハック可能 ✓

#16866. 水母与传说之下

統計

Flowey 在 Snowdin 埋下了一枚炸弹!

炸弹的计时器初始值为 $b$。每一秒,计时器都会减少 1。当计时器达到 0 时,炸弹就会爆炸!为了给 Snowdin 的居民争取足够的撤离时间,你需要尽可能延长炸弹爆炸的时间。

你有 $n$ 个工具。每个工具最多只能使用一次。如果你使用第 $i$ 个工具,计时器会增加 $x_i$。然而,如果计时器被改变为大于 $a$ 的整数,由于程序错误,计时器会被重置为 $a$。

具体来说,每一秒会按以下顺序发生事件:

  1. 你可以选择一些(可能不选)之前未使用过的工具。如果你选择第 $i$ 个工具,且炸弹当前的计时器值为 $c$,则计时器将变为 $\min(c + x_i, a)$。
  2. 计时器减少 1。
  3. 如果计时器达到 0,炸弹爆炸。

Jellyfish 现在想知道,如果最优地使用这些工具,炸弹爆炸前的最大秒数是多少。

输入格式

每个测试包含多个测试用例。第一行包含测试用例的数量 $t$ ($1 \le t \le 2000$)。接下来是各测试用例的描述。

每个测试用例的第一行包含三个整数 $a, b, n$ ($1 \le b \le a \le 10^9, 1 \le n \le 100$),分别表示炸弹计时器的最大值、计时器的初始值以及工具的数量。

每个测试用例的第二行包含 $n$ 个整数 $x_1, x_2, \dots, x_n$ ($1 \le x_i \le 10^9$),表示使用第 $i$ 个工具时计时器可以增加的数值。

注意,所有测试用例中 $n$ 的总和没有限制。

输出格式

对于每个测试用例,输出一个整数,表示炸弹爆炸前的最大秒数。

样例

输入格式 1

2
5 3 3
1 1 7
7 1 5
1 2 5 6 8

输出格式 1

9
21

说明

设 $c$ 为炸弹计时器的值。在第一个测试用例中:

  • 第 1 秒:在这一秒选择工具 1 和 2,此时 $c = 5$;计时器减少 1,变为 $c = 4$。
  • 第 2 秒:计时器减少 1,变为 $c = 3$。
  • 第 3 秒:计时器减少 1,变为 $c = 2$。
  • 第 4 秒:计时器减少 1,变为 $c = 1$。
  • 第 5 秒:选择工具 3,此时 $c = 5$;计时器减少 1,变为 $c = 4$。
  • 第 6 秒:计时器减少 1,变为 $c = 3$。
  • 第 7 秒:计时器减少 1,变为 $c = 2$。
  • 第 8 秒:计时器减少 1,变为 $c = 1$。
  • 第 9 秒:计时器减少 1,变为 $c = 0$。炸弹爆炸。

可以证明,不存在任何使用工具的方法能使炸弹在 9 秒之后才爆炸。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.