알고리즘

[Lv_2] 택배 배달과 수거

빅디 2023. 8. 17. 23:51
728x90
def solution(cap, n, deliveries, pickups):

    answer = 0
    deli_cap = 0
    pick_cap = 0

    for i in range(n-1, -1, -1):

        count = 0

        deli_cap -= deliveries[i]
        pick_cap -= pickups[i]

        while deli_cap < 0 or pick_cap < 0:
            deli_cap += cap
            pick_cap += cap
            count += 1

        answer += (i + 1) * 2 * count
    return answer