#P17297. [ICPC 2026 Xi'an I] Qenerals

    ID: 19707 远端评测题 1000ms 512MiB 尝试: 7 已通过: 2 显示难度普及 上传者: 标签>模拟贪心ICPC2026省赛/邀请赛西安

[ICPC 2026 Xi'an I] Qenerals

Problem Description

Yuki is playing a game called Qenerals.

At time t=0t = 0, Yuki has x=0x = 0 soldiers and occupies y=1y = 1 fortress. There are nn unoccupied fortresses on the map, where the ii-th fortress has a parameter aia_i.

The game lasts for mm seconds. For each positive integer ii such that 1im1 \le i \le m:

  • At the beginning of the ii-th second, each fortress occupied by Yuki produces 11 soldier, i.e., xx+yx \leftarrow x + y.
  • At the end of the ii-th second, Yuki can perform any number of operations (including zero). In each operation, Yuki chooses an unoccupied fortress jj such that ajxa_j \le x, consumes aja_j soldiers, and occupies fortress jj, i.e., xxajx \leftarrow x - a_j and yy+1y \leftarrow y + 1.

You need to help Yuki determine the maximum number of soldiers she can have after the game ends.

Input Format

This problem contains multiple test cases.

The first line contains a positive integer tt (1t105)(1 \le t \le 10^5), representing the number of test cases.

For each test case:

  • The first line contains two positive integers n,mn, m (1n5105, 1m109)(1 \le n \le 5\cdot10^5,\ 1 \le m \le 10^{9}).
  • The second line contains nn positive integers a1,,ana_1, \dots, a_n (1ai109)(1 \le a_i \le 10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 51055\cdot10^5.

Output Format

For each test case, output a single line containing an integer representing the maximum number of soldiers Yuki can have after the game ends.

3
2 3
2 1
3 6
1 1 3
3 5
1 1 1
4
13
12

Hint

For the first test case:

  • At the beginning of the 11-st second, the number of fortresses occupied by Yuki is y=1y = 1, so the number of soldiers xx increases from 00 to 11.
  • At the end of the 11-st second, Yuki can choose to occupy the 22-nd fortress, so yy increases from 11 to 22, and xx decreases from 11 to 00.
  • At the beginning of the 22-nd second, y=2y = 2, so xx increases from 00 to 22.
  • At the end of the 22-nd second, Yuki can choose not to perform any operations.
  • At the beginning of the 33-rd second, y=2y = 2, so xx increases from 22 to 44.
  • At the end of the 33-rd second, Yuki can choose not to perform any operations.
  • After the game ends, the number of soldiers xx is 44. It can be proven that 44 is the maximum number of soldiers Yuki can have.

For the second test case:

  • Yuki can occupy the 11-st, 22-nd, and 33-rd fortresses at the end of the 11-st, 22-nd, and 33-rd seconds respectively, allowing her to have 1313 soldiers after the game ends.

For the third test case:

  • Yuki can occupy the 11-st fortress at the end of the 11-st second, and the 22-nd and 33-rd fortresses at the end of the 22-nd second, allowing her to have 1212 soldiers after the game ends.