Calculating Minimum Training Hours to Win a Competition
IntuitionThe problem requires determining the minimum number of training hours needed to ensure that you can defeat all opponents in a competition. My first tho
# Intuition
The problem requires determining the minimum number of training hours needed to ensure that you can defeat all opponents in a competition. My first thought was to calculate the required energy and experience separately and then sum the necessary training hours.

# Approach
1. Calculate Required Energy: Determine the total energy required to defeat all opponents and compare it with the initial energy. The difference (plus one if necessary) gives the number of training hours needed for energy.
2. Calculate Required Experience: Iterate through the opponents and ensure that the initial experience is always greater than the opponent's experience. If not, calculate the required training hours to increase the experience.
3. Sum Training Hours: Sum the training hours required for energy and experience to get the total minimum training hours.

# Complexity
- Time complexity: $$O(n)$$

- Space complexity: $$O(1)$$

# Code
```cpp []
class Solution {
public:
    int minNumberOfHours(int initialEnergy, int initialExperience, vector<int>& energy, vector<int>& experience) {
        int x=-initialEnergy;
        for (int i=0;i<energy.size();i++){x+=energy[i];}
        if (x<0){x=0;}
        else {x++;}
        int o=0;
        for (int i=0;i<experience.size();i++){
            while (initialExperience<=experience[i]){
                initialExperience++;o++;
            }
            initialExperience+=experience[i];
        }
        return x+o;
    }
};
```
['C++']