-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNo_1966.java
More file actions
57 lines (49 loc) · 1.63 KB
/
No_1966.java
File metadata and controls
57 lines (49 loc) · 1.63 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
53
54
55
56
57
/*
Problem_1966_프린터 큐
https://www.acmicpc.net/problem/1966
*/
import java.io.*;
import java.util.*;
public class No_1966 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer st;
LinkedList<int[]> ll = new LinkedList<>();
int testCase = Integer.parseInt(br.readLine());
for (int test = 0; test < testCase; test++) {
ll.clear();
st = new StringTokenizer(br.readLine(), " ");
int repeat = Integer.parseInt(st.nextToken());
int tmp = Integer.parseInt(st.nextToken());
int res = 0;
st = new StringTokenizer(br.readLine(), " ");
for (int i = 0; i < repeat; i++) {
int current = Integer.parseInt(st.nextToken());
ll.add(new int[]{i, current});
}
while (!ll.isEmpty()) {
int[] check = ll.poll();
boolean able = true;
for (int[] k : ll) {
if (check[1] < k[1]) {
able = false;
}
}
if (able) {
res++;
if (check[0] == tmp) {
break;
}
}
else {
ll.add(check);
}
}
bw.write(res + "\n");
}
bw.flush();
bw.close();
br.close();
}
}