-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJesseCookies.java
More file actions
36 lines (34 loc) · 1.01 KB
/
JesseCookies.java
File metadata and controls
36 lines (34 loc) · 1.01 KB
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
33
34
35
36
/**
* Created by MalhotR1 on 05/03/2017.
*/
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.Arrays;
public class JesseCookies {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] in = br.readLine().trim().split(" ");
int N = Integer.parseInt(in[0]);
int K = Integer.parseInt(in[1]);
in = br.readLine().trim().split(" ");
int[] arr = new int[N];
int count = 0;
for (int i = 0; i < N; i++) {
arr[i] = Integer.parseInt(in[i]);
if (arr[i] < K) count++;
}
Arrays.sort(arr);
count--;
int i = 1;
int steps = 0;
while(count-- > 0) {
arr[i] = 2 * arr[i] + arr[i-1];
if (arr[i] < K) i++;
else i += 2;
steps++;
}
System.out.println(steps);
}
}