[프로그래머스] 택배배달과 수거하기

yewon Lee·2023년 7월 27일
0


😎코딩테스트 연습>2023 KAKAO BLIND RECRUITMENT>택배 배달과 수거하기


📘 문제풀이

def solution(cap, n, deliveries, pickups):
    answer = 0 
    
    have_to_deli = 0
    have_to_pick = 0

    for i in range(n-1, -1, -1):
        have_to_deli += deliveries[i]
        have_to_pick += pickups[i]

        while have_to_deli > 0 or have_to_pick > 0:
            have_to_deli -= cap
            have_to_pick -= cap
            answer += (i+1) * 2            
    
    return answer

참고링크

profile
시작

1개의 댓글

comment-user-thumbnail
2023년 7월 27일

글 잘 봤습니다.

답글 달기