-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBJAlgo_1966.java
More file actions
39 lines (33 loc) · 1.3 KB
/
Copy pathBJAlgo_1966.java
File metadata and controls
39 lines (33 loc) · 1.3 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
37
38
39
import java.io.*;
import java.util.*;
public class BJAlgo_1966 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int testCase = Integer.parseInt(br.readLine());
for (int i = 0; i < testCase; i++) {
int[] nm = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
Queue<int[]> queue = new LinkedList();
int[] priority = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
for (int index = 0; index < nm[0]; index++) {
int[] tmp = new int[2];
tmp[0] = priority[index];
tmp[1] = index;
queue.offer(tmp);
}
int count = 0;
while (true) {
if (queue.peek()[0] == queue.stream().max((a, b) -> a[0] - b[0]).orElse(new int[1])[0]) {
count++;
if (queue.peek()[1] == nm[1]) {
System.out.println(count);
break;
} else {
queue.remove();
}
} else {
queue.add(queue.remove());
}
}
}
}
}