728x90
문제 설명
이 문제는 게임을 하다 보면 치료를 통해 게임 캐릭터의 피를 회복하는 경우를 문제로 하고 있다.


def solution(bandage, health, attacks):
answer = health
healing = 0
t = 0
max_time = attacks[-1][0]
at = {}
for i in range(len(attacks)):
at[attacks[i][0]] = attacks[i][1]
while t <= max_time:
if t in at:
healing = 0
answer -= at[t]
if answer <= 0:
return -1
else:
healing += 1
if healing < bandage[0]:
answer += bandage[1]
if answer > health:
answer = health
else:
answer += bandage[1] + bandage[2]
if answer > health:
answer = health
healing = 0
t += 1
return answer
문제 링크: https://school.programmers.co.kr/learn/courses/30/lessons/250137
728x90
'알고리즘' 카테고리의 다른 글
[프로그래머스/코딩테스트 연습] 연속 부분 수열 합의 개수 ( 파이썬 ) (0) | 2024.01.10 |
---|---|
[프로그래머스/PCCP_9번] 이웃한 칸 ( 파이썬 ) (0) | 2024.01.05 |
[백준/13335] 트럭 (파이썬) (0) | 2023.12.29 |
[백준/15664] N과 M (10) ( 파이썬 ) (0) | 2023.12.15 |
[백준/1600] 말이 되고픈 원숭이 (파이썬) (0) | 2023.12.12 |