-
Notifications
You must be signed in to change notification settings - Fork 0
/
2383. 赢得比赛需要的最少训练时长.cpp
36 lines (32 loc) · 1.31 KB
/
2383. 赢得比赛需要的最少训练时长.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class Solution {
public:
int minNumberOfHours(int initialEnergy, int initialExperience, vector<int>& energy, vector<int>& experience) {
int th=0;
for(int i=0;i<energy.size();i++){
if(initialEnergy>energy[i]){
if(initialExperience >experience[i]){
initialEnergy-=energy[i];
initialExperience+=experience[i];
}else{
th+=abs(experience[i]-initialExperience)+1;
initialEnergy-=energy[i];
initialExperience+=abs(experience[i]-initialExperience)+1;
initialExperience+=experience[i];
}
}else{
if(initialExperience>experience[i]){
th+=abs(energy[i]-initialEnergy)+1;
initialEnergy=1;
initialExperience+=experience[i];
}else{
th+=abs(energy[i]-initialEnergy)+1;
initialEnergy=1;
th+=abs(experience[i]-initialExperience)+1;
initialExperience+=abs(experience[i]-initialExperience)+1;
initialExperience+=experience[i];
}
}
}
return th;
}
};