문제
풀이
#include <string>
#include <vector>
#include <queue>
using namespace std;
int solution(vector<int> scoville, int K) {
priority_queue<int, vector<int>, greater<int>> pq;
int answer = 0;
for(int i = 0; i < scoville.size(); i++)
{
pq.push(scoville[i]);
}
int first(0), second(0);
while(pq.top() < K)
{
if(pq.size() <= 1)
return -1;
first = pq.top();
pq.pop();
second = pq.top();
pq.pop();
first = first + second * 2;
pq.push(first);
answer++;
}
return answer;
}
결과
걸린 시간
40분
'개발 > 알고리즘' 카테고리의 다른 글
프로그래머스 피보나치 수 C++ (0) | 2020.12.15 |
---|---|
프로그래머스 N개의 최소공배수 (0) | 2020.12.15 |
프로그래머스 멀쩡한 사각형 C++ (0) | 2020.12.15 |
프로그래머스 큰 수 만들기 C++ (0) | 2020.12.13 |
프로그래머스 숫자의 표현 C++ (0) | 2020.12.13 |