[프로그래머스] [PCCP 기출문제] 1번 / 붕대 감기

yewon Lee·2023년 11월 28일
0


😎코딩테스트 연습>PCCP 기출문제>[PCCP 기출문제] 1번


📘 문제풀이

def solution(bandage, health, attacks):
    T = 0 #전체시간
    ct = 0 #회복지속시간
    h = health
    
    #at 공격시간,  피해량
    for at, a in attacks:
        ct = at - T -1

        #회복량
        h += ct * bandage[1]
        #추가회복량
        while ct >= bandage[0]:
            h += bandage[2]
            ct -= bandage[0]
        #체력보정    
        if h > health:
            h = health
        #공격피해
        h -= a
        #죽음
        if h <= 0:
            return -1
        #현재시간
        T = at
        
    return h
현재 시간에서 공격 당한 그 시간 사이만큼 회복 가능
연속으로 공격 당하면 회복x
profile
시작

0개의 댓글