1076: The battle to the enemy
[Creator : ]
Description
You are on a solo mission and face N enemies. The strength of the ith enemy is Ai ; You start with an initial strength of H and a resistance level of X.
Here are the rules of the fight:
- If an enemy's strength is less than or equal to your resistance X, you win without losing any strength.
-
If an enemy's strength exceeds your resistance, you can still win, but only if your strength is strictly greater than the enemy's.
In this case, your strength decreases by the enemy's strength after the battle.
Your task is to find the minimum resistance value X that you need to defeat all N enemies while ensuring you maintains a positive strength after the last battle.
Please node you fight the enemy according to their order provided in the list.
Input
Input Format
- The first line of input will contain a single integer T, denoting the number of test cases.
-
Each test case consists of two lines of input.
- The first line of each test case contains two space-separated integers N and H — the number of enemies and your initial strength, respectively.
- The next line contains N space-separated integers the strengths of the N enemies.
Output
Output Format
For each test case, output on a new line, the minimum resistance value X that you needs to defeat all N enemies while ensuring he maintains a positive strength after the last battle.
Constraints
1 <= T < 10001 <= N, H, Ai <= 100000
The sum of all N over all the test cases won't exceed 1000,000
Sample Input Copy
3
2 5
3 1
3 5
2 1 3
5 20
12 4 5 2 3
Sample Output Copy
0
2
4