#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<algorithm>
using namespace std;
typedef struct Job
{
int pr;
bool flag;
}Job;
int main()
{
int T;cin >> T;
while (T--)
{
queue<Job> q;
priority_queue<int> pq;
int n, m;cin >> n >> m;
for(int i=0;i<n;i++)
{
int p;cin >> p;
Job j = { p,i==m? true :false };
q.push(j);pq.push(p);
}
int time = 0;
while (true)
{
Job J = q.front();q.pop();
if (J.pr != pq.top())
{
q.push(J);
}
else
{
time++;
pq.pop();
if (J.flag)break;
}
}
cout << time << endl;
}
return 0;
}
队首的位置是0比较麻烦,所以用了结构体,在里面加了个flag用来标记我们关注的是哪一个任务。然后跟着题意模拟就行了
优先队列是方便判断优先级的。