프로그래머스 - 더 맵게(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
Author And Source
이 문제에 관하여(프로그래머스 - 더 맵게(lv2)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@imalive77/프로그래머스-더-맵게lv2저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)