프로그래머스 - 더 맵게(lv2)

#include <string>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;



int solution(vector<int> scoville, int K) {
    int answer = 0;

priority_queue<int, vector<int>, greater<int>> pq(scoville.begin(), scoville.end());
    
    while(pq.size() > 1 && pq.top()<K)
    {
        int first = pq.top();
        pq.pop();
        int second = pq.top();
        pq.pop();
        
        int New = first+ second*2;
        pq.push(New);
        answer++;
    }
	if( pq.top()<K) return -1;
 
    return answer;

}

while(pq.size() > 1
부분이랑
if( pq.top()<K) return -1;
부분 처리를 못했었었다.

[[[[[[[[priority_queue]]]]]]]]]]]
https://hyeonstorage.tistory.com/315

좋은 웹페이지 즐겨찾기