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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
| function solution(bandage, health, attacks) {
const length = attacks.length;
let ss = 0;
let heal = health;
//시간 설정
for(var i = 1 ; i <= attacks[attacks.length-1][0]; i++){
let attacked = false;
const time = i;
//console.log("time : " + time);
for(var j = 0; j < attacks.length ; j++){
//console.log("attack : " + attacks[j][0]);
if(time == attacks[j][0]){
ss= 0;
heal = heal - attacks[j][1];
attacked = true;
break;
}
}
if(heal <= 0){
return -1;
}
if(!attacked){
if(heal < health){
heal += bandage[1];
}
//if(i != 0){}
ss += 1;
if(ss == bandage[0] ){
ss = 0;
heal += bandage[2];
if(heal >= health){
heal = health;
}
}
}
if(heal <= 0){
return -1;
}
//console.log("heal :" + heal);
}
return heal;
}
|