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.