3207. Maximum Points After Enemy Battles Medium

@problem@discussion
#Array#Greedy



1/**
2 * [3207] Maximum Points After Enemy Battles
3 *
4 * You are given an integer array enemyEnergies denoting the energy values of various enemies.
5 * You are also given an integer currentEnergy denoting the amount of energy you have initially.
6 * You start with 0 points, and all the enemies are unmarked initially.
7 * You can perform either of the following operations zero or multiple times to gain points:
8 * 
9 * 	Choose an unmarked enemy, i, such that currentEnergy >= enemyEnergies[i]. By choosing this option:
10 * 	
11 * 		You gain 1 point.
12 * 		Your energy is reduced by the enemy's energy, i.e. currentEnergy = currentEnergy - enemyEnergies[i].
13 * 	
14 * 	
15 * 	If you have at least 1 point, you can choose an unmarked enemy, i. By choosing this option:
16 * 	
17 * 		Your energy increases by the enemy's energy, i.e. currentEnergy = currentEnergy + enemyEnergies[i].
18 * 		The <font face="monospace">e</font>nemy i is marked.
19 * 	
20 * 	
21 * 
22 * Return an integer denoting the maximum points you can get in the end by optimally performing operations.
23 *  
24 * <strong class="example">Example 1:
25 * <div class="example-block">
26 * Input: <span class="example-io">enemyEnergies = [3,2,2], currentEnergy = 2</span>
27 * Output: <span class="example-io">3</span>
28 * Explanation:
29 * The following operations can be performed to get 3 points, which is the maximum:
30 * 
31 * 	First operation on enemy 1: points increases by 1, and currentEnergy decreases by 2. So, points = 1, and currentEnergy = 0.
32 * 	Second operation on enemy 0: currentEnergy increases by 3, and enemy 0 is marked. So, points = 1, currentEnergy = 3, and marked enemies = [0].
33 * 	First operation on enemy 2: points increases by 1, and currentEnergy decreases by 2. So, points = 2, currentEnergy = 1, and marked enemies = [0].
34 * 	Second operation on enemy 2: currentEnergy increases by 2, and enemy 2 is marked. So, points = 2, currentEnergy = 3, and marked enemies = [0, 2].
35 * 	First operation on enemy 1: points increases by 1, and currentEnergy decreases by 2. So, points = 3, currentEnergy = 1, and marked enemies = [0, 2].
36 * </div>
37 * <strong class="example">Example 2:
38 * <div class="example-block">
39 * Input: <span class="example-io">enemyEnergies = </span>[2]<span class="example-io">, currentEnergy = 10</span>
40 * Output: <span class="example-io">5</span>
41 * Explanation: 
42 * Performing the first operation 5 times on enemy 0 results in the maximum number of points.
43 * </div>
44 *  
45 * Constraints:
46 * 
47 * 	1 <= enemyEnergies.length <= 10^5
48 * 	1 <= enemyEnergies[i] <= 10^9
49 * 	0 <= currentEnergy <= 10^9
50 * 
51 */
52pub struct Solution {}
53
54// problem: https://leetcode.com/problems/maximum-points-after-enemy-battles/
55// discuss: https://leetcode.com/problems/maximum-points-after-enemy-battles/discuss/?currentPage=1&orderBy=most_votes&query=
56
57// submission codes start here
58
59impl Solution {
60    pub fn maximum_points(enemy_energies: Vec<i32>, current_energy: i32) -> i64 {
61        
62    }
63}
64
65// submission codes end
66
67#[cfg(test)]
68mod tests {
69    use super::*;
70
71    #[test]
72    fn test_3207() {
73    }
74}
75


Back
© 2025 bowen.ge All Rights Reserved.