[프로그래머스] 다리를 지나는 트럭
#include <string>
#include <vector>
#include <queue>
using namespace std;
int solution(int bridge_length, int weight, vector<int> truck_weights) {
int answer = 0;
queue<int> q;
for(int i=0; i<bridge_length; ++i){
q.push(0);
}
int totalW = 0;
int cnt = 0;
int idx = 0;
while(cnt < truck_weights.size()){
answer++;
if(q.front() != 0){
cnt++;
totalW -= q.front();
}
q.pop();
if(totalW + truck_weights[idx] <= weight){
q.push(truck_weights[idx]);
totalW += truck_weights[idx];
idx++;
}
else{
q.push(0);
}
}
return answer;
}