3207. Maximum Points After Enemy Battles
You are given an integer array
enemyEnergiesdenoting the energy values of various enemies.You are also given an integer
currentEnergydenoting 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,
i, such thatcurrentEnergy >= enemyEnergies[i]. By choosing this option:
- You gain 1 point.
- Your energy is reduced by the enemy’s energy, i.e.
currentEnergy = currentEnergy - enemyEnergies[i].If you have at least 1 point, you can choose an unmarked enemy,
i. 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.
1 | class Solution { |