Created
September 21, 2019 02:01
-
-
Save surinoel/2fb2504cae8aa731d53272cf18d2023b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <queue> | |
#include <iostream> | |
#include <functional> | |
using namespace std; | |
int solution(vector<int> scoville, int K) { | |
int answer = 0; | |
priority_queue<int, vector<int>, greater<int>> pq; | |
for (int i = 0; i < scoville.size(); i++) { | |
pq.push(scoville[i]); | |
} | |
while (1) { | |
if (pq.size() <= 1) { | |
return -1; | |
} | |
if (pq.top() >= K) { | |
break; | |
} | |
int a = pq.top(); | |
pq.pop(); | |
int b = pq.top(); | |
pq.pop(); | |
int c = a + b * 2; | |
pq.push(c); | |
answer += 1; | |
} | |
return answer; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment