forked from GreatAlgorithm-Study/AlgorithmStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJY_42626.java
More file actions
25 lines (24 loc) · 720 Bytes
/
JY_42626.java
File metadata and controls
25 lines (24 loc) · 720 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
import java.util.*;
class JY_42626 {
public int solution(int[] scoville, int K) {
int answer = 0;
PriorityQueue<Integer> pq = new PriorityQueue<>();
for (int i = 0; i < scoville.length; i++){
pq.add(scoville[i]);
}
while (pq.size() != 1){
int s1 = pq.poll();
if (s1 >= K) break;
else{
int s2 = pq.poll();
int newS = s1 + (s2*2);
pq.add(newS);
answer += 1;
}
}
// System.out.println(pq);
// 가장 맵지않은 스코빌 지수가 K보다 작으면 -1
if (pq.peek() < K) return -1;
return answer;
}
}