https://programmers.co.kr/learn/courses/30/lessons/42583
function solution(bridge_length, weight, truck_weights) {
let queue = new Array(bridge_length).fill(0); //queue의 길이
let moving_truck = truck_weights.shift(); //현재 다리를 건너고 있는 트럭
let total_weight = 0; //현재 다리를 건너는 트럭의 총 무게
let time = 0; //걸린 시간
queue.unshift(moving_truck);
queue.pop();
total_weight += moving_truck;
time++;
while(total_weight) {
total_weight -= queue.pop();
moving_truck = truck_weights.shift();
if(moving_truck <= weight - total_weight) {
queue.unshift(moving_truck);
total_weight += moving_truck;
} else {
queue.unshift(0);
truck_weights.unshift(moving_truck);
}
time++;
}
return time;
}