题解
#include <queue>
queue <int> q;//q存储下标
vector <int > a, b;//a存储输入 b存储排序后的优先级
int main()
{
int n;
cin >> n;//需要处理数据 数量
int x;//队列长度
int m;//关注任务所在下标
for (int i = 0; i < n; i++)
{
cin >> x >> m;
int w;
for (int j = 0; j < x; j++)
{
cin >> w;
q.push(j);
b.push_back(w);
a.push_back(w);
}
sort(b.begin(), b.end(), greater<int>());//
int l = 0;//指向b[0]=4
int k = 0;//计时器
while (!q.empty())
{
int t = q.front();
int max = b[l];
if (a[t] < max)
{
q.pop();
q.push(t);//t往后走
}
else
{
if (t == m)
{
cout << ++k<<endl;
break;
}
else {
q.pop();
l++;
k++;
}
}
}
}
return 0;
}