https://school.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>> q;
for (const auto& e : scoville) q.push(e);
int first, second, result;
while (true) {
if (q.top() >= K) break;
else if (q.size() <= 1) return -1;
else {
first = q.top(); q.pop();
second = q.top(); q.pop();
result = first + (second * 2);
q.push(result), answer++;
}
}
return answer;
}
'Coding Test > Programmers' 카테고리의 다른 글
[Programmers] (2019 KAKAO BLIND RECRUITMENT) Lv 2. 오픈채팅방 (0) | 2023.07.09 |
---|---|
[Programmers] (2022 KAKAO BLIND RECRUITMENT) Lv 2. 주차 요금 계산 (0) | 2023.07.07 |
[Programmers] (2018 KAKAO BLIND RECRUITMENT) Lv 2. [3차] n진수 게임 (0) | 2023.07.03 |
[Programmers] (2018 KAKAO BLIND RECRUITMENT) Lv 2. [3차] 압축 (0) | 2023.07.03 |
[Programmers] (2022 KAKAO BLIND RECRUITMENT) Lv 2. k진수에서 소수 개수 구하기 (0) | 2023.06.26 |
댓글