forked from GreatAlgorithm-Study/AlgorithmStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDH_42626.java
More file actions
32 lines (26 loc) · 711 Bytes
/
DH_42626.java
File metadata and controls
32 lines (26 loc) · 711 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.*;
/*
더 맵게
*/
public class DH_42626 {
class Solution {
public int solution(int[] scoville, int K) {
int answer = 0;
PriorityQueue<Integer> pq = new PriorityQueue<>();
for(int i: scoville) pq.add(i);
boolean isMake = false;
while(true) {
if(pq.peek() >= K) {
isMake = true;
break;
}
if(pq.size() == 1) break;
int p1 = pq.poll(), p2 = pq.poll();
pq.add(p1 + (p2 * 2));
answer++;
}
if(!isMake) answer = -1;
return answer;
}
}
}