Tap here to switch tabs
Problem
Submissions

Problem: Maximum Points After Enemy Battles

Maximum Points After Enemy Battles gives you enemy energies and starting energy. Choose unmarked enemies to spend energy for points or use points to gain energy from them, then return the maximum points possible.

Statement

You are given an integer array enemyEnergies where each element represents the energy value of an enemy, and an integer currentEnergy representing your initial energy.

You start with 00 points, and all enemies are initially unmarked. You may perform either of the following operations any number of times to accumulate points:

Operation 1 — Choose an unmarked enemy i such that currentEnergy >= enemyEnergies[i]:

  • Your points increase by 11.

  • Your energy decreases: currentEnergy = currentEnergy - enemyEnergies[i].

Operation 2 — If you have at least 11 point, choose any unmarked enemy i:

  • Your energy increases: currentEnergy = currentEnergy + enemyEnergies[i].

  • Enemy i becomes marked.

Return the maximum number of points you can achieve by performing these operations optimally.

Constraints:

  • 1≤1 \leq enemyEnergies.length ≤105\leq 10^5

  • 1≤1 \leq enemyEnergies[i] ≤109\leq 10^9

  • 0≤0 \leq currentEnergy ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Points After Enemy Battles

Maximum Points After Enemy Battles gives you enemy energies and starting energy. Choose unmarked enemies to spend energy for points or use points to gain energy from them, then return the maximum points possible.

Statement

You are given an integer array enemyEnergies where each element represents the energy value of an enemy, and an integer currentEnergy representing your initial energy.

You start with 00 points, and all enemies are initially unmarked. You may perform either of the following operations any number of times to accumulate points:

Operation 1 — Choose an unmarked enemy i such that currentEnergy >= enemyEnergies[i]:

  • Your points increase by 11.

  • Your energy decreases: currentEnergy = currentEnergy - enemyEnergies[i].

Operation 2 — If you have at least 11 point, choose any unmarked enemy i:

  • Your energy increases: currentEnergy = currentEnergy + enemyEnergies[i].

  • Enemy i becomes marked.

Return the maximum number of points you can achieve by performing these operations optimally.

Constraints:

  • 1≤1 \leq enemyEnergies.length ≤105\leq 10^5

  • 1≤1 \leq enemyEnergies[i] ≤109\leq 10^9

  • 0≤0 \leq currentEnergy ≤109\leq 10^9