/ ALGORITHM

프로그래머스 - 다리 위를 지나는 트럭

image-20230125193546531

from collections import deque

def solution(bridge_length, weight, truck_weights):
    standby = deque(truck_weights)
    bridge = deque([0]*bridge_length)
    totalweight=0
    sec=0
    
    while standby or totalweight>0:
        totalweight -= bridge.pop()
        
        if standby and standby[0]+totalweight<=weight:
            front = standby.popleft()
            totalweight+=front
            bridge.appendleft(front) 
            
        else:
            bridge.appendleft(0)    
            
        sec+=1
    return sec