-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1966.java
54 lines (41 loc) · 1.31 KB
/
1966.java
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
import java.util.*;
public class Main {
static class Pair {
int num, pri;
Pair(int num, int pri) {this.num=num; this.pri=pri;}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int tcNum = sc.nextInt();
while(tcNum-- > 0) {
int n = sc.nextInt();
int m = sc.nextInt();
Queue<Pair> q = new LinkedList<>();
for(int i=0; i<n; i++)
q.add(new Pair(i, sc.nextInt()));
int order = 0;
Pair now = null;
while(true) {
// 우선순위가 가장 높은 프린터물이 now에 걸릴때까지 반복
while (now == null) {
now = q.remove();
for (Pair p : q) {
if (p.pri > now.pri) {
q.add(now);
now = null;
break;
}
}
}
// 찾아야할 순서의 프린트물이면 정지
order++;
if(now.num == m) {
System.out.println(order);
break;
}
else
now = null;
}
}
}
}