Infernos CodeChef Solution | CodeChef Problem Solution 2022
Ved started playing a new mobile game called Fighting Clans. An army of enemies is approaching his base. The enemy has health points. An enemy gets killed if his health points become .
Ved defends his base using a weapon named Inferno
. He can set the Inferno
to one of the following two modes:
- Single-Target Mode: In one second, the
Inferno
can target exactly one living enemy and cause damage of at most health points. - Multi-Target Mode: In one second, the
Inferno
can target all living enemies and cause damage of health point to each of them.
Find the minimum time required to kill all the enemies.
Note: Ved is not allowed to change the mode of the weapon once it is set initially.
Input Format
- The first line contains a single integer - the number of test cases. Then the test cases follow.
- The first line of each test case contains two integers and - the number of enemies and the damage caused by the single-target mode of
Inferno
in one second respectively.
- The second line of each test case contains space-separated integers where denotes the initial health points of enemy.
Output Format
For each test case, output in a single line, the minimum time required to kill all the enemies.
Constraints
Sample Input 1
4
5 4
2 2 4 1 1
3 5
5 4 5
4 4
4 4 4 4
3 10
7 8 9
Sample Output 1
4
3
4
3
Explanation
Test case 1: In single-target mode, all enemies can be killed in second each. Thus, in single-target mode, the total time required is seconds.
In multi-target mode:
- After one second, the health points of the enemies are: . Enemies and are dead after one second.
- After two seconds, the health points of the enemies are: .
- After three seconds, the health points of the enemies are: .
- After four seconds, the health points of the enemies are: .
Thus, seconds are required to kill enemies using multi-target mode. The minimum time required to kill all the enemies is seconds.
Test case 2: In single-target mode, all enemies can be killed in second each. Thus, in single-target mode, the total time required is seconds.
In multi-target mode:
- After one second, the health points of the enemies are: .
- After two seconds, the health points of the enemies are: .
- After three seconds, the health points of the enemies are: .
- After four seconds, the health points of the enemies are: .
- After five seconds, the health points of the enemies are: .
Thus, seconds are required to kill enemies using multi-target mode. The minimum time required to kill all the enemies is seconds.
Test case 3: Here, single-target mode will take seconds and multi-target mode will also take seconds. Therefore, the minimum time required is seconds.
Test case 4: Here, single-target mode will take seconds, while multi-target mode will take seconds. Therefore, the minimum time required is seconds.
Join Now for Solution:-
No comments:
Post a Comment