#include <iostream>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;
#define y front().first
#define x front().second
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int tc; cin >> tc;
for (int i = 0; i < tc; i++)
{
// 문서의 개수와 몇번째로 인쇄되었는지 확인
int t, f, cnt = 0;
cin >> t >> f;
queue<pair<int, int>> q;
priority_queue<int> pq;
for (int j = 0; j < t; j++)
{
int val; cin >> val;
q.push({ j,val });
pq.push(val);
}
while (!q.empty())
{
int curIdx = q.y, curVal = q.x;
q.pop();
if (pq.top() == curVal)
{
pq.pop();
cnt++;
if (curIdx == f)
{
cout << cnt << '\n';
break;
}
}
else
q.push({curIdx, curVal});
}
}
return 0;
}
'코딩테스트 > 백준' 카테고리의 다른 글
[골5] 9663 - N-Queen (0) | 2022.08.30 |
---|---|
[골5] 14503 - 로봇 청소기 (0) | 2022.08.28 |
[실3] 1021 - 회전하는 큐 (0) | 2022.08.26 |
[골5] 2023 - 신기한 소수 (0) | 2022.08.26 |
[골2] 10800 - 컬러볼 (0) | 2022.08.26 |