- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1966.java
More file actions
Latest commit
54 lines (41 loc) · 1.31 KB
/
Copy path1966.java
File metadata and controls
54 lines (41 loc) · 1.31 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
importjava.util.*;
publicclassMain {
staticclassPair {
intnum, pri;
Pair(intnum, intpri) {this.num=num; this.pri=pri;}
}
publicstaticvoidmain(String[] args) {
Scannersc = newScanner(System.in);
inttcNum = sc.nextInt();
while(tcNum-- > 0) {
intn = sc.nextInt();
intm = sc.nextInt();
Queue<Pair> q = newLinkedList<>();
for(inti=0; i<n; i++)
q.add(newPair(i, sc.nextInt()));
intorder = 0;
Pairnow = null;
while(true) {
// 우선순위가 가장 높은 프린터물이 now에 걸릴때까지 반복
while (now == null) {
now = q.remove();
for (Pairp : 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;
}
}
}
}