QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 512 MB مجموع النقاط: 100 قابلة للهجوم ✓

#17345. Qenerals

الإحصائيات

Yuki 正在玩一个名为 Qenerals 的游戏。

在时间 $t = 0$ 时,Yuki 拥有 $x = 0$ 名士兵,并占领了 $y = 1$ 座堡垒。地图上还有 $n$ 座未被占领的堡垒,其中第 $i$ 座堡垒有一个参数 $a_i$。

游戏持续 $m$ 秒。对于满足 $1 \le i \le m$ 的每个正整数 $i$:

  • 在第 $i$ 秒开始时,Yuki 占领的每座堡垒都会生产 $1$ 名士兵,即 $x \leftarrow x + y$。
  • 在第 $i$ 秒结束时,Yuki 可以进行任意次数的操作(包括零次)。在每次操作中,Yuki 选择一座未被占领的堡垒 $j$,满足 $a_j \le x$,消耗 $a_j$ 名士兵,并占领堡垒 $j$,即 $x \leftarrow x - a_j$ 且 $y \leftarrow y + 1$。

你需要帮助 Yuki 确定游戏结束时她能拥有的最大士兵数量。

输入格式

本题包含多个测试用例。

第一行包含一个正整数 $t$ ($1 \le t \le 10^5$),表示测试用例的数量。

对于每个测试用例:

  • 第一行包含两个正整数 $n, m$ ($1 \le n \le 5 \cdot 10^5$, $1 \le m \le 10^9$)。
  • 第二行包含 $n$ 个正整数 $a_1, \dots, a_n$ ($1 \le a_i \le 10^9$)。

保证所有测试用例中 $n$ 的总和不超过 $5 \cdot 10^5$。

输出格式

对于每个测试用例,输出一行,包含一个整数,表示游戏结束时 Yuki 能拥有的最大士兵数量。

样例

输入样例 1

3
2 3
2 1
3 6
1 1 3
3 5
1 1 1

输出样例 1

4
13
12

说明

对于第一个测试用例:

  • 在第 $1$ 秒开始时,Yuki 占领的堡垒数量为 $y = 1$,因此士兵数量 $x$ 从 $0$ 增加到 $1$。
  • 在第 $1$ 秒结束时,Yuki 可以选择占领第 $2$ 座堡垒,因此 $y$ 从 $1$ 增加到 $2$,$x$ 从 $1$ 减少到 $0$。
  • 在第 $2$ 秒开始时,$y = 2$,因此 $x$ 从 $0$ 增加到 $2$。
  • 在第 $2$ 秒结束时,Yuki 可以选择不进行任何操作。
  • 在第 $3$ 秒开始时,$y = 2$,因此 $x$ 从 $2$ 增加到 $4$。
  • 在第 $3$ 秒结束时,Yuki 可以选择不进行任何操作。
  • 游戏结束后,士兵数量 $x$ 为 $4$。可以证明 $4$ 是 Yuki 所能获得的最大士兵数量。

对于第二个测试用例:

  • Yuki 可以分别在第 $1$ 秒、第 $2$ 秒和第 $3$ 秒结束时占领第 $1$、第 $2$ 和第 $3$ 座堡垒,从而在游戏结束时拥有 $13$ 名士兵。

对于第三个测试用例:

  • Yuki 可以在第 $1$ 秒结束时占领第 $1$ 座堡垒,并在第 $2$ 秒结束时占领第 $2$ 和第 $3$ 座堡垒,从而在游戏结束时拥有 $12$ 名士兵。

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.