매일 C++ day 1
2021-05-17
테스트 테스트
https://programmers.co.kr/learn/courses/30/lessons/42626
#include <string>
#include <vector>
#include <queue>
#include <functional>
using namespace std;
void mixSco(priority_queue<int, vector<int>, greater<int>> &sco)
{
int temp = sco.top();
sco.pop();
int temp2 = sco.top();
sco.pop();
int newSco = temp + (temp2 * 2);
sco.push(newSco);
}
int solution(vector<int> scoville, int K) {
int answer = 0;
priority_queue<int, vector<int>, greater<int>> sco;
for(auto it : scoville) {
sco.push(it);
}
while(sco.size() > 1 && sco.top() < K)
{
mixSco(sco);
answer+=1;
}
if(sco.top()<K) answer = -1;
return answer;
}
test test