public int solution(int[] bandage, int health, int[][] attacks) {
int castTime = bandage[0];
int healingPerSecond = bandage[1];
int additionalHealing = bandage[2];
int maxHealth = health;
int preAttackTime = attacks[0][0];
for (int[] attack : attacks) {
int attackTime = attack[0];
int damage = attack[1];
int timeBetween = attackTime - preAttackTime - 1;
if (timeBetween > 0) {
health += (timeBetween * healingPerSecond);
health += ((timeBetween / castTime) * additionalHealing);
if (health > maxHealth) {
health = maxHealth;
}
}
health -= damage;
if (health <= 0) {
return -1;
}
preAttackTime = attackTime;
}
return health;
}
출처:https://school.programmers.co.kr/learn/courses/30/lessons/250137