-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathSolution.java
More file actions
31 lines (26 loc) · 737 Bytes
/
Solution.java
File metadata and controls
31 lines (26 loc) · 737 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
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
PriorityQueue<Integer> q = new PriorityQueue<>();
for (int i = 0; i < n; i++) {
int tmp = sc.nextInt();
q.add(tmp);
}
int counter = 0;
while (q.size() > 1 && q.peek() <= k) {
int first = q.poll();
int second = q.poll();
q.add(first + 2 * second);
counter++;
}
if (q.peek() < k) {
System.out.println(-1);
} else {
System.out.println(counter);
}
}
}