#P12821. [NERC 2021] Heroes of Might

[NERC 2021] Heroes of Might

题目描述

Recently, Hellen played her favorite game "Heroes of Might". She had a hero with only one Rust dragon, which was attacked by another hero with a lot of peasants. Another hero had nn groups of peasants, ii-th of them had aia_i peasants in it. Unfortunately, Hellen lost that battle, but now she is wondering how big the health of the Rust dragon should be to win against such a big army of peasants?

Let's discuss how the battle goes. Initially, the Rust dragon has hdh_d health points, and each peasant has hph_p health points. So ii-th group of peasants has a total of H=hpaiH = h_p \cdot a_i health points at the start of the battle. The battle consists of several rounds. In each round, two things happen:

  • First, $\textbf{the dragon chooses one group of peasants and attacks it}$. The health of that group is decreased by the dragon's damage rating dd. If the group has zero or less health points, it is destroyed and is removed from the game.
  • Second, $\textbf{each one of the peasant groups attacks the dragon}$. A group with the total current health HH has Hhp\lceil\frac{H}{h_p}\rceil peasants still alive and each of them decreases the dragon's health by one.

If the dragon's health becomes zero or less at any point, it dies and Hellen loses. If all peasant groups are destroyed, Hellen wins the battle.

You need to determine the smallest possible hdh_d, which could make Hellen win if she chooses targets on each turn optimally.

输入格式

The first line of the input contains an integer tt (1t10001 \le t \le 1000) --- the number of test cases you need to solve.

Each of the test cases is described by two lines. The first line contains three numbers nn (1n10001 \le n \le 1000), dd (1d1091 \le d \le 10^9), and hph_p (1hp1091 \le h_p \le 10^9) --- the number of peasant groups, the dragon's damage rating, and the health of each peasant. The second line contains nn numbers aia_i (1ai109;hpai1091 \le a_i \le 10^9; h_p \cdot \sum{a_i} \le 10^9) --- the number of peasants in each group.

The sum of nn over all test cases does not exceed 10001000.

输出格式

For each test case, output one number --- the smallest amount of health hdh_d that the dragon should have for Hellen to win the battle. If the dragon is never attacked by a peasant, it should still have positive health, so output 1 in this case.

4
1 15 10
4
1 10 1
10
2 15 10
4 5
2 11 15
10 17
5
1
26
504

提示

In the third test case, the optimal Hellen's strategy leads to the following battle. At the start, the dragon has hd=26h_d=26 health points, and two groups of peasants have H1=410H_1=4\cdot10 and H2=510H_2=5\cdot10 health points. We'll denote them as H1=40(4)H_1=40(4) and H2=50(5)H_2=50(5), placing the value of Hhp\lceil\frac{H}{h_p}\rceil in the brackets.

$$\begin{array}{c} h_d=26, H_1=40(4), H_2=50(5) & \text{Round 1} & \textbf{The dragon attacks the first group}, \text{dealing 15 damage, leaving}\ H_1=25(3). \\ h_d=26, H_1=25(3), H_2=50(5) & & \text{Peasants attack the dragon}, \text{dealing 3+5 damage, leaving}\ h_d=18. \\ h_d=18, H_1=25(3), H_2=50(5) & \text{Round 2} & \textbf{The dragon attacks the first group}, \text{dealing 15 damage, leaving}\ H_1=10(1). \\ h_d=18, H_1=10(1), H_2=50(5) & & \text{Peasants attack the dragon}, \text{dealing 1+5 damage, leaving}\ h_d=12. \\ h_d=12, H_1=10(1), H_2=50(5) & \text{Round 3} & \textbf{The dragon attacks the second group}, \text{dealing 15 damage, leaving}\ H_2=35(4). \\ h_d=12, H_1=10(1), H_2=35(4) & & \text{Peasants attack the dragon}, \text{dealing 1+4 damage, leaving}\ h_d=7. \\ h_d=7, H_1=10(1), H_2=35(4) & \text{Round 4} & \textbf{The dragon attacks the second group}, \text{dealing 15 damage, leaving}\ H_2=20(2). \\ h_d=7, H_1=10(1), H_2=20(2) & & \text{Peasants attack the dragon}, \text{dealing 1+2 damage, leaving}\ h_d=4. \\ h_d=4, H_1=10(1), H_2=20(2) & \text{Round 5} & \textbf{The dragon attacks the second group}, \text{dealing 15 damage, leaving}\ H_2=5(1) \\ h_d=4, H_1=10(1), H_2=5(1) & & \text{Peasants attack the dragon}, \text{dealing 1+1 damage, leaving}\ h_d=2. \\ h_d=2, H_1=10(1), H_2=5(1) & \text{Round 6} & \textbf{The dragon attacks the second group}, \text{destroying it, so it is removed from the game.} \\ h_d=2, H_1=10(1) & & \text{Peasants attack the dragon}, \text{dealing 1 damage, leaving}\ h_d=1. \\ h_d=1, H_1=10(1) & \text{Round 7} & \textbf{The dragon attacks the first group}, \text{destroying it, so it is removed from the game.} \\ h_d=1 & \text{Game over} & \text{The dragon is still alive, Hellen wins.} \end{array}$$