Minimum Hours of Training to Win a Competition Solution in C++
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(n)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(1)\n# Code\n```\nclass Solution {\npublic:\n    int minNumberOfHours(int initialEnergy, int initialExperience, vector<int>& energy, vector<int>& experience) {\n        int i, flag=1, ans=0;\n        for(i=0 ; i<energy.size() ; i++)\n        {\n            if(experience[i]<initialExperience)\n            {\n                initialExperience += experience[i];\n            }\n            else if(experience[i]>=initialExperience)\n            {\n                ans += experience[i] - initialExperience + 1;\n                initialExperience += 2*experience[i] - initialExperience + 1;\n            }\n            if(energy[i]<initialEnergy)\n            {\n                initialEnergy -= energy[i];\n            }\n            else if(energy[i]>=initialEnergy)\n            {\n                ans += energy[i] - initialEnergy + 1;\n                initialEnergy = 1;\n            }\n        }\n        return ans;\n    }\n};\n```\n![upvote new.jpg](https://assets.leetcode.com/users/images/0f95901e-4be5-4d52-b6bb-1df2ff572fc4_1682781377.0021822.jpeg)\n
['C++']