#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N;
cin >> N;
for (int i = 0; i < N; i++)
{
int M, Q;
cin >> M >> Q;
queue<pair<int, int>> tasks;
priority_queue<int> maxHeap;
for (int j = 0; j < M; j++)
{
int num;
cin >> num;
tasks.emplace(num, j);
maxHeap.push(num);
}
int answer = 0;
while (true)
{
int value = tasks.front().first;
int index = tasks.front().second;
tasks.pop();
if (value == maxHeap.top())
{
maxHeap.pop();
answer++;
if (index == Q)
{
cout << answer << "\n";
break;
}
}
else
{
tasks.emplace(value, index);
}
}
}
return 0;
}
'개발일지 > 알고리즘' 카테고리의 다른 글
백준 6603번 : 로또 (0) | 2025.02.02 |
---|---|
백준 5430번 : AC (0) | 2025.01.28 |
백준 1158번 : 요세푸스 문제 (0) | 2025.01.25 |
백준 1874번 : 스택 수열 (0) | 2025.01.25 |
백준 9012번 : 괄호 (0) | 2025.01.24 |