Minimum Training Hours to Defeat All Opponents
IntuitionWe need to train enough to ensure we have more energy and experience than each opponent. Training should be done efficiently to minimize the total numb
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
We need to train enough to ensure we have more energy and experience than each opponent. Training should be done efficiently to minimize the total number of hours. This is essentially a simulation problem where we adjust our experience and energy based on the opponents' stats.

# Approach
<!-- Describe your approach to solving the problem. -->
Simulation of battles:

Iterate through each opponent.
For each opponent, first check if your current energy is sufficient to defeat them. If not, train to make it sufficient.
Next, check if your experience is sufficient to defeat the opponent. If not, train to make it sufficient.
After defeating each opponent, update your energy and experience.
Energy and Experience Updates:

After defeating an opponent, your experience is incremented by the opponent's experience, and your energy is reduced by the opponent's energy.
Final Adjustment:

If at any point your energy is below 1 after defeating all opponents, you will need to train to ensure you have at least 1 energy.
# Complexity
Time complexity:
$$O(n)$$
We iterate through each opponent once, so the time complexity is linear in terms of the number of opponents.

Space complexity:
$$O(1)$$
We only use a few extra variables to track the required training hours, so the space complexity is constant.

# Code
```cpp []
class Solution {
public:
    int minNumberOfHours(int initialEnergy, int initialExperience,
                         vector<int>& energy, vector<int>& experience) {
        int req_E = 0;
        
        // Traverse through each opponent.
        for (int i = 0; i < energy.size(); i++) {
            initialEnergy -= energy[i];  // Deduct energy required to fight the opponent

            // If experience is insufficient, we need to train more
            if (initialExperience <= experience[i]) {
                req_E += experience[i] - initialExperience + 1;  // Train the required amount
                initialExperience = experience[i] + 1;  // Alice's experience after training
            }
            
            // After defeating the opponent, increase experience
            initialExperience += experience[i];
        }

        // If energy is below 1 after all the battles, train to get it back to 1
        if (initialEnergy < 1) {
            req_E += abs(initialEnergy) + 1;
        }

        return req_E;
    }
};

```
['C++']