-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
59 lines (49 loc) · 1.6 KB
/
Main.java
File metadata and controls
59 lines (49 loc) · 1.6 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
58
59
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;
class Print{
int idx;
int importance;
public Print(int idx, int importance){
this.idx = idx;
this.importance = importance;
}
}
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int testCase = sc.nextInt();
for(int i=0; i<testCase; i++){
int N = sc.nextInt();
int IDX = sc.nextInt();
Queue<Print> printer = new LinkedList<Print>();
List<Integer> importanceList = new ArrayList<Integer>();
for(int j=0; j<N; j++){
int importance = sc.nextInt();
importanceList.add(importance);
printer.add(new Print(j, importance));
}
Collections.sort(importanceList, (e1, e2)->{
return Integer.compare(e1, e2);
}); // asc
int cnt = 0;
while(!printer.isEmpty()){
if(printer.peek().importance == importanceList.get(importanceList.size()-1)){
Print isAnswer = printer.poll();
cnt++;
if(isAnswer.idx == IDX){
System.out.println(cnt);
break;
}
importanceList.remove(importanceList.size()-1);
} else {
printer.add(printer.poll());
}
}
}
sc.close();
}
}