Simulate the Story || Greedy || linear time || Clean Java Code
Complexity
Time complexity: O(n)

Space complexity: O(1)
Code
# Complexity
- Time complexity: $$O(n)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: $$O(1)$$
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    public int minNumberOfHours(int initialEnergy, int initialExperience, int[] energy, int[] experience) {
        int cost = 0;
        for (int i = 0; i < energy.length; i++) {
            if (initialEnergy <= energy[i]) {
                int diff = energy[i] - initialEnergy + 1;
                initialEnergy += diff;
                cost += diff;
            }
            if (initialExperience <= experience[i]) {
                int diff = experience[i] - initialExperience + 1;
                initialExperience += diff;
                cost += diff;
            }
            initialEnergy -= energy[i];
            initialExperience += experience[i];
        }
        return cost;
    }
}
```
['Array', 'Greedy', 'Simulation', 'Java']