跳至主要内容

3207. Maximum Points After Enemy Battles

#define ll long long
class Solution {
public:
long long maximumPoints(vector<int>& enemyEnergies, int currentEnergy)
{
sort(enemyEnergies.begin(), enemyEnergies.end());
int n = enemyEnergies.size();

if (currentEnergy < enemyEnergies[0]) return 0;

ll availableEngergy = currentEnergy;
for (int j = n - 1; j > 0; --j)
{
availableEngergy += enemyEnergies[j];
}
return availableEngergy / enemyEnergies[0];
}
};
  • T: O(nlogn)O(n \cdot \log n)
  • S: O(1)O(1)