Maximum Points After Enemy Battles
You are given an integer array enemyEnergies denoting the energy values of various enemies.
You are also given an integer currentEnergy denoting the amount of energy you have initially.
You start with 0 points, and all the enemies are unmarked initially.
You can perform either of the following operations zero or multiple times to gain points:
- Choose an unmarked enemy
isuch thatcurrentEnergy >= enemyEnergies[i]. By choosing this option: - You gain
1point. - Your energy is reduced by the enemy's energy, i.e.
currentEnergy = currentEnergy - enemyEnergies[i]. - If you have at least
1point, you can choose an unmarked enemyi. By choosing this option: - Your energy increases by the enemy's energy, i.e.
currentEnergy = currentEnergy + enemyEnergies[i]. - The enemy
iis marked.
Return an integer denoting the maximum points you can get in the end by optimally performing operations.
Example 1
Input
enemyEnergies = [3,2,2], currentEnergy = 2Output
3The described sequence of operations reaches 3 points, which is the maximum possible.
Example 2
Input
enemyEnergies = [2], currentEnergy = 10Output
5Performing the first operation 5 times on enemy 0 results in the maximum number of points.
Constraints
- 1 <= enemyEnergies.length <= 10^5
- 1 <= enemyEnergies[i] <= 10^9
- 0 <= currentEnergy <= 10^9