문제

풀이
def solution(bandage, health, attacks):
#최대 체력, 현재 시간 설정
max_health = health
time_now = 0
for attack in attacks :
#현재 시간에서 다음 공격까지는 붕대를 감는 시간
healing_time = attack[0] - time_now
#healing time
#붕대 감기 시전시간 이상의 healing time있을 시에, 추가 회복
if healing_time // bandage[0] >= 1 :
health += (healing_time // bandage[0]) * bandage[2]
#초당 회복량
health += healing_time * bandage[1]
#max_health를 넘을 수 없으므로
if health > max_health :
health = max_health
#attack
health -= attack[1]
if health <= 0 :
return -1
#공격 이후부터 회복을 시작하므로 time_now 설정
time_now = attack[0] + 1
return health
1. 최대 체력(max_health), 현재 시간(time_now)설정
2. 현재시간 ~ 다음 공격까지 붕대를 감는 시간(healing time)
3. healing time이 붕대감기 시전 시간보다 클 경우, 추가 회복량 계산
4. healing time 동안 초당 회복량 계산, 하지만 max_health넘을 수 없음
5. attack time : 체력이 0 이하가 되면 -1 return 하면서 break
6. 공격 다음 초부터 붕대를 감기 시작하므로 time_now를 attack시점부터 + 1
7. 모든 공격이 끝난 후 health return
GitHub Link ←
BackJoon-Programmers/프로그래머스/1/250137. [PCCP 기출문제] 1번 / 붕대 감기 at main · jaeheonk
Contribute to jaeheonki/BackJoon-Programmers development by creating an account on GitHub.
github.com
'Algorithm' 카테고리의 다른 글
| [프로그래머스] 짝지어 제거하기 (4) | 2026.04.01 |
|---|---|
| [프로그래머스] 최댓값과 최솟값 (2) | 2026.03.30 |
| [프로그래머스] 달리기 경주 (0) | 2026.03.23 |
| [프로그래머스] 개인정보 수집 유효기간 (3) | 2026.03.20 |
| [프로그래머스] [PCCE 기출문제] 10번 / 데이터 분석 (0) | 2026.03.20 |
