-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj1966.java
More file actions
52 lines (41 loc) · 1.3 KB
/
boj1966.java
File metadata and controls
52 lines (41 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
40
41
42
43
44
45
46
47
48
49
50
51
52
import java.util.LinkedList;
import java.util.Scanner;
public class boj1966 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
StringBuilder sb = new StringBuilder();
int T = sc.nextInt();
while (T-- > 0) {
int N = sc.nextInt();
int M = sc.nextInt();
LinkedList<int[]> q = new LinkedList<>();
for (int i = 0; i < N; i++) {
q.offer(new int[] { i, sc.nextInt() });
}
int cnt = 0;
while (!q.isEmpty()) {
int[] first = q.poll();
boolean isMax = true;
for (int i = 0; i < q.size(); i++) {
if (first[1] < q.get(i)[1]) {
q.offer(first);
for (int j = 0; j < i; j++) {
q.offer(q.poll());
}
isMax = false;
break;
}
}
if (isMax == false) {
continue;
}
cnt++;
if (first[0] == M) {
break;
}
}
sb.append(cnt).append('\n');
}
System.out.println(sb);
}
}