Universal Cup Judging System

Universal Cup

时间限制: 1 s 内存限制: 512 MB 总分: 100 可 Hack ✓
统计

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 揀一座滿足 $a_j \le x$ 而且未被佔領嘅堡壘 $j$,消耗 $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, \ldots, 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.