import java.util.*;
class Person {
int id;
int priority;
public Person(int id, int priority) {
this.id = id;
this.priority = priority;
}
}
class Main {
public int solution(int N, int M, Queue<Person> q) {
int answer = 1;
while (!q.isEmpty()) {
Person tmp = q.poll();
for (Person x : q) {
if (tmp.priority < x.priority) {
q.offer(tmp);
tmp = null;
break;
}
}
if (tmp != null) {
if (tmp.id == M)
return answer;
else
answer++;
}
}
return answer;
}
public static void main(String[] args) {
Main T = new Main();
Scanner kb = new Scanner(System.in);
int N = kb.nextInt();
int M = kb.nextInt();
Queue<Person> q = new LinkedList<>();
for (int i = 0; i < N; i++) {
q.offer(new Person(i, kb.nextInt()));
}
System.out.print(T.solution(N, M, q));
kb.close();
}
}
알고리즘/JAVA
댓글