Easy Beginners Solutions || Explained || C++
\nclass Solution {\npublic:\n    int minNumberOfHours(int initialEnergy, int initialExperience, vector<int>& energy, vector<int>& experience) {\n        int Tot
```\nclass Solution {\npublic:\n    int minNumberOfHours(int initialEnergy, int initialExperience, vector<int>& energy, vector<int>& experience) {\n        int TotalEnemyEnergy=0 , myExp=initialExperience , expTraining=0;\n        \n        for(int e:energy) TotalEnemyEnergy += e;  //total energy required to defeat enemy.\n        \n        //for experience training.\n        for(int i=0;i<experience.size();i++){  //check enemies in order.\n            if(myExp<=experience[i]){  //if training required to fight ith enemy.\n                expTraining += experience[i] - myExp + 1;  //calculate how much to train.\n                myExp += expTraining;  //increase exp after training.\n            }\n            myExp += experience[i];  //increase exp after defeating enemy.\n        }\n        if(initialEnergy>TotalEnemyEnergy) return expTraining;//iniatially energy is more than enough..check training required only for exp. \n        return (TotalEnemyEnergy-initialEnergy+1 + expTraining);  \n    }\n};\n```
['C']