Skip to content

Latest commit

 

History

History
42 lines (34 loc) · 1.34 KB

delivery_service.md

File metadata and controls

42 lines (34 loc) · 1.34 KB

delivery service(택배배달과 수거하기)

  • input
cap n deliveries pickups result
4 5 [1, 0, 3, 1, 2] [0, 3, 0, 4, 0] 16
2 7 [1, 0, 2, 0, 1, 0, 2] [0, 2, 0, 1, 0, 2, 0] 30

image

  • solve
def solution(cap, n, deliveries, pickups):
    answer = 0
    while deliveries and not deliveries[-1]:
        deliveries.pop()
    while pickups and not pickups[-1]:
        pickups.pop()
    while deliveries or pickups:
        answer += 2 * max(len(deliveries), len(pickups))

        deliver_left = pickup_left = cap
        while deliveries:
            if deliveries[-1] <= deliver_left:
                deliver_left -= deliveries[-1]
                deliveries.pop()
            else:
                deliveries[-1] -= deliver_left
                break
        while pickups:
            if pickups[-1] <= pickup_left:
                pickup_left -= pickups[-1]
                pickups.pop()
            else:
                pickups[-1] -= pickup_left
                break

    return answer