|
| 1 | +3207\. Maximum Points After Enemy Battles |
| 2 | + |
| 3 | +Medium |
| 4 | + |
| 5 | +You are given an integer array `enemyEnergies` denoting the energy values of various enemies. |
| 6 | + |
| 7 | +You are also given an integer `currentEnergy` denoting the amount of energy you have initially. |
| 8 | + |
| 9 | +You start with 0 points, and all the enemies are unmarked initially. |
| 10 | + |
| 11 | +You can perform **either** of the following operations **zero** or multiple times to gain points: |
| 12 | + |
| 13 | +* Choose an **unmarked** enemy, `i`, such that `currentEnergy >= enemyEnergies[i]`. By choosing this option: |
| 14 | + * You gain 1 point. |
| 15 | + * Your energy is reduced by the enemy's energy, i.e. `currentEnergy = currentEnergy - enemyEnergies[i]`. |
| 16 | +* If you have **at least** 1 point, you can choose an **unmarked** enemy, `i`. By choosing this option: |
| 17 | + * Your energy increases by the enemy's energy, i.e. `currentEnergy = currentEnergy + enemyEnergies[i]`. |
| 18 | + * The enemy `i` is **marked**. |
| 19 | + |
| 20 | +Return an integer denoting the **maximum** points you can get in the end by optimally performing operations. |
| 21 | + |
| 22 | +**Example 1:** |
| 23 | + |
| 24 | +**Input:** enemyEnergies = [3,2,2], currentEnergy = 2 |
| 25 | + |
| 26 | +**Output:** 3 |
| 27 | + |
| 28 | +**Explanation:** |
| 29 | + |
| 30 | +The following operations can be performed to get 3 points, which is the maximum: |
| 31 | + |
| 32 | +* First operation on enemy 1: `points` increases by 1, and `currentEnergy` decreases by 2. So, `points = 1`, and `currentEnergy = 0`. |
| 33 | +* Second operation on enemy 0: `currentEnergy` increases by 3, and enemy 0 is marked. So, `points = 1`, `currentEnergy = 3`, and marked enemies = `[0]`. |
| 34 | +* First operation on enemy 2: `points` increases by 1, and `currentEnergy` decreases by 2. So, `points = 2`, `currentEnergy = 1`, and marked enemies = `[0]`. |
| 35 | +* Second operation on enemy 2: `currentEnergy` increases by 2, and enemy 2 is marked. So, `points = 2`, `currentEnergy = 3`, and marked enemies = `[0, 2]`. |
| 36 | +* First operation on enemy 1: `points` increases by 1, and `currentEnergy` decreases by 2. So, `points = 3`, `currentEnergy = 1`, and marked enemies = `[0, 2]`. |
| 37 | + |
| 38 | +**Example 2:** |
| 39 | + |
| 40 | +**Input:** enemyEnergies = [2], currentEnergy = 10 |
| 41 | + |
| 42 | +**Output:** 5 |
| 43 | + |
| 44 | +**Explanation:** |
| 45 | + |
| 46 | +Performing the first operation 5 times on enemy 0 results in the maximum number of points. |
| 47 | + |
| 48 | +**Constraints:** |
| 49 | + |
| 50 | +* <code>1 <= enemyEnergies.length <= 10<sup>5</sup></code> |
| 51 | +* <code>1 <= enemyEnergies[i] <= 10<sup>9</sup></code> |
| 52 | +* <code>0 <= currentEnergy <= 10<sup>9</sup></code> |
0 commit comments