다리를 지나는 트럭

ddo_h·2020년 7월 21일
0
#include <string>
#include <vector>
#include <queue>
#include <iostream>

using namespace std;

int solution(int bridge_length, int weight, vector<int> truck_weights) {
    int cnt = 0;
    int sum = 0;
    queue<int> truck_list;
    queue<int> curr;
    for(int i = 0; i < truck_weights.size(); i++)
        truck_list.push(truck_weights[i]);
    
    for(int i = 0; i < bridge_length; i++)
        curr.push(0);

    do{
        //cout<< cnt << ": " << curr.front() << endl;
        cnt++;
        sum -= curr.front();
        curr.pop();
        
        if(truck_list.empty()) continue;
        
        int temp = truck_list.front();
        if(sum+temp > weight){
            curr.push(0);
            continue;
        }
        
        curr.push(temp);
        sum += temp;
        truck_list.pop();
    }while(!curr.empty());
    
    return cnt;
}
profile
열심히!

0개의 댓글