작성자 없음
작성자 정보가 삭제된 글입니다.
작성
·
473
·
수정됨
0
테스트 5에서 오류가 나던데 뭐가 문제인지를 못찾겠어요ㅠ
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
class Person implements Comparable<Person> {
int id;
int priority;
public Person(int id, int priority) {
this.id = id;
this.priority = priority;
}
@Override
public int compareTo(Person o) {
return o.priority - this.priority;
}
}
public class Main {
public static int solution(int n, int m, int[] arr) {
int answer = 0;
Queue<Person> queue = new PriorityQueue<>();
for(int i=0; i<n; i++) {
queue.offer(new Person(i, arr[i]));
}
while(!queue.isEmpty()) {
Person tmp = queue.poll();
answer++;
if(tmp.priority == arr[m] && tmp.id == m) {
return answer;
}
}
return answer;
}
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
int[] arr = new int[n];
for (int i=0; i<n; i++) {
arr[i] = in.nextInt();
}
System.out.println(solution(n, m, arr));
}
}