스택이용 풀이
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
int solution(int bridge_length, int weight, vector<int> truck_weights) {
int time = 0;
int idx = 0;
int sum = 0;
queue<int> on_bridge;
while(1) {
if(idx == truck_weights.size()) {
time += bridge_length;
break;
}
time++;
int tmp = truck_weights[idx];
if(on_bridge.size() == bridge_length) {
sum -= on_bridge.front();
on_bridge.pop();
}
if(sum + tmp <= weight) {
sum += tmp;
on_bridge.push(tmp);
idx++;
}else {
on_bridge.push(0);
}
}
return time;
}