https://programmers.co.kr/learn/courses/30/lessons/42626
#include <string>
#include <vector>
#include <queue>
using namespace std;
int solution(vector<int> scoville, int K) {
int answer = 0;
priority_queue<int,vector<int>, greater<int>> sco;
for(int i=0;i<scoville.size();i++){
sco.push(scoville[i]);
}
int addK =0;
while(sco.top() < K){
addK = sco.top(); // 제일 낮음
sco.pop();
if(sco.empty()) // 마지막
return -1;
addK += sco.top()*2; // 그 다음 낮음
sco.pop();
sco.push(addK); // 추가
answer++;
}
return answer;
}
#include <vector>
#include <queue>
using namespace std;
int solution(vector<int> scoville, int K) {
int answer = 0;
int needHot;
priority_queue<int,vector<int>,greater<int>> pq (scoville.begin(),scoville.end());
while(pq.top()<K) {
if(pq.size()==1) return answer = -1;
needHot=pq.top(); pq.pop();
pq.push(needHot+pq.top()*2);
pq.pop(); answer++;
}
return answer;
}