링크 : https://school.programmers.co.kr/learn/courses/30/lessons/42583
#include <string>
#include <vector>
#include <queue>
using namespace std;
int solution(int bridge_length, int weight, vector<int> truck_weights) {
int answer = 0;
int index = 0;
int sum = 0;
queue<int> q;
while(1){
if(index == truck_weights.size()){
answer += bridge_length;
break;
}
answer ++;
int tmp = truck_weights[index];
if(q.size() == bridge_length){
sum -= q.front();
q.pop();
}
if(sum + tmp <= weight){
q.push(tmp);
sum += tmp;
index ++;
}
else{
q.push(0);
}
}
return answer;
}