import java.util.LinkedList;
import java.util.Queue;
public class Solution {
public int solution(int bridge_length, int weight, int[] truck_weights) {
int time = 0;
int currentWeight = 0;
Queue<Integer> bridge = new LinkedList<>();
for (int truckWeight : truck_weights) {
while (true) {
if (bridge.isEmpty()) {
bridge.offer(truckWeight);
currentWeight += truckWeight;
time++;
break;
} else if (bridge.size() == bridge_length) {
currentWeight -= bridge.poll();
} else {
if (currentWeight + truckWeight <= weight) {
bridge.offer(truckWeight);
currentWeight += truckWeight;
time++;
break;
} else {
bridge.offer(0);
time++;
}
}
}
}
return time + bridge_length;
}
}
어휴 머리아파
이 문제는 내일의 나에게로 보내봅니다 🙈