Gidhub BE Developer

[Programmers] 42587. 프린터

2018-09-27
goodGid

Problem

Problem URL : 프린터


[1] Answer Code (18. 09. 27)

#include <string>
#include <vector>
#include <queue>
#include <iostream>
#define p pair<int,int>
using namespace std;

int solution(vector<int> priorities, int location) {
    int answer = 0;
    queue<p> q;
    priority_queue<int> pq;
    int size = (int) priorities.size();
    for(int i=0; i<size; i++){
        q.push( {priorities[i],i} );
        pq.push(priorities[i]);
    }

    while(! q.empty()){
        int value = q.front().first;
        int idx = q.front().second;
        q.pop();
        if( pq.top() == value){
            pq.pop();
            answer++;
            if(idx == location)
                break;
        }
        else{
            q.push( {value,idx} );
        }
    }
    return answer;
}

Review


Comments

Content