Skip to content

Commit

Permalink
이슈 #408에서 솔루션 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Dec 2, 2024
1 parent 833f7c7 commit e1ade24
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions Programmers/더_맵게.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <string>
#include <vector>
#include <queue>

using namespace std;

int solution(vector<int> scoville, int K) {
priority_queue<int, vector<int>, greater<int>> pq;

for (int s : scoville) {
pq.push(s);
}

int mixCount = 0;

while (pq.size() >= 2 && pq.top() < K) {
int first = pq.top();
pq.pop();
int second = pq.top();
pq.pop();

int newScoville = first + (second * 2);
pq.push(newScoville);
mixCount++;
}

return (pq.top() >= K) ? mixCount : -1;
}

0 comments on commit e1ade24

Please sign in to comment.