import java.util.*;
import java.io.*;
// defalt bandage[1] 만큼 회복 else -공격
// bandage[0]초 => bandage[2] 추가 회복
// [시전 시간, 초당 회복량, 추가 회복량] 최대 100
// [공격 시간, 피해량] 이미 정렬
class Solution{
public int solution(int[] bandage, int health, int[][] attacks){
int attackCnt = 0,heelCnt = 0;
int firstAttack = attacks[0][0];
int lastAttack = attacks[attacks.length - 1][0];
int maxHealth = health;
for(int t = firstAttack; t <= lastAttack; t++){
if(t == attacks[attackCnt][0]){
health -= attacks[attackCnt][1];
attackCnt++;
heelCnt = 0;
}
else{
heelCnt++;
health += bandage[1];
if(heelCnt == bandage[0]){
health += bandage[2];
heelCnt = 0;
}
if (health > maxHealth) health = maxHealth;
}
if(health <= 0) return -1;
}
return health;
}
public static void main(String[] args){
Solution sol = new Solution();
// 예제 데이터
int[] bandage = {1, 1, 1};
int health = 5;
int[][] attacks = {{1,2}, {3,2}};
int result = sol.solution(bandage, health, attacks);
System.out.println("Result: " + result);
}
}
'백준 & 프로그래머스' 카테고리의 다른 글
프로그래머스.[PCCP 모의고사 1] 4번.python (0) | 2023.12.02 |
---|---|
[PCCP 모의고사 #1] 3번 - 유전법칙 (0) | 2023.11.30 |
프로그래머스.주차 요금 계산.py (1) | 2023.11.28 |
백준.가운데를 말해요.1665.py (0) | 2023.10.06 |
백준.다각형의 면적.2103.java (0) | 2023.09.26 |
댓글