Train of thought: Each task is queued in the order in which it is entered, and the priority is saved in another array, and then sorted in order from large to small, or from little to large, representing the order of each execution. The queue is then manipulated, first from the queue to remove an element, to determine whether the index of the array and the number of equal, if equal, the printing time of +1, while the array subscript +1 or-1, if not equal, then directly to the end of the team, to start the next cycle.
(beginning to understand the wrong idea, that is, the highest priority in the queue to remove the task directly, while ignoring the queue can only one out)
Import Java.util.Arrays;
Import java.util.LinkedList;
Import Java.util.Queue;
Import Java.util.Scanner;
public class Main {public
static void Main (string[] args) {
Scanner scan = new Scanner (system.in);
int t = Scan.nextint ();
while (T--! =0) {
int n = scan.nextint ();
int m = Scan.nextint ();
queue<num> q = new linkedlist<> ();
int[] A = new Int[n];
for (int i=0;i<n;i++) {
int p = scan.nextint ();
num num = new num (p,i);
Q.add (num);
A[i] = p;
}
Arrays.sort (A);
int j = n-1;
int cnt = 0;
Boolean ok = false;
while (!OK) {
num num = Q.peek ();
Q.poll ();
if (Num.value==a[j]) {
cnt++;
j--;
if (num.pos==m) {
ok = true;
}
} else{
q.add (num);
}
}
SYSTEM.OUT.PRINTLN (CNT);
}
Static class num{
int value;
int pos;
Public Num (int value,int pos) {
this.value = value;
This.pos = pos;
}
}