문제: https://school.programmers.co.kr/learn/courses/30/lessons/250137
class Solution {
public int solution(int[] bandage, int health, int[][] attacks) {
int maxHealth = health;
int len = attacks[attacks.length -1][0]; // 반복 초
int attackIdx = 0; // 공격 위치
int success = 0; // 연속 성공 시간
int needTime = bandage[0]; // 시전 시간
int heal = bandage[1]; // 초당 회복량
int plusheal = bandage[2]; // 추가 회복량
for(int i = 0; i <= len; i++){
int attackTime = attacks[attackIdx][0]; // 공격 시간
int attackPower = attacks[attackIdx][1]; // 피해량
if(i == attackTime){
health -= attackPower;
if(health <= 0) return -1;
attackIdx++;
success = 0;
continue;
}
health += heal;
success++;
// 추가 회복량
if(success == needTime){
health += plusheal;
success = 0;
}
// 최대 회복량 제한
if(health > maxHealth) health = maxHealth;
}
return health;
}
}
```