본문 바로가기
백준

[1966] 프린터 큐

by Jcoder 2018. 7. 22.


#include <iostream>
#include <queue>
using namespace std;
int main()
{
int i, testcase;
cin >> testcase;
for (i = 0; i < testcase; i++)
{
queue<pair<int, int>> q;
priority_queue <int> pq;
int n, m, cnt = 0;
cin >> n >> m;
for (int j = 0; j < n; j++)
{
int a;
cin >> a;
q.push({ j, a });
pq.push(a);
}
while (!q.empty())
{
int index = q.front().first;
int val = q.front().second;
q.pop();
if (pq.top() == val)
{
pq.pop();
cnt++;
if (index == m)
{
cout << cnt << endl;
break;
}
}
else
q.push({ index, val });
}
}
return 0;
}


'백준' 카테고리의 다른 글

[10866] 덱  (0) 2018.07.22
[1158], [11866] 조세퍼스 문제  (0) 2018.07.22
[10845] 큐  (0) 2018.07.22
[2504] 괄호의 값  (0) 2018.07.22
[9012] 괄호  (0) 2018.07.22