-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1966.cpp
More file actions
53 lines (48 loc) · 787 Bytes
/
1966.cpp
File metadata and controls
53 lines (48 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// 1966. 프린터 큐
// 2019.05.19
// 브루트 포스, 큐, 시뮬레이션
#include<string>
#include<queue>
#include<iostream>
using namespace std;
int main()
{
int t;
cin >> t;
while (t > 0)
{
t--;
int n, m, answer = 0;
cin >> n >> m;
queue <pair<int, int>> q;
priority_queue <int> pq; // 우선순위 큐 선언
for (int i = 0; i < n; i++)
{
int tmp;
cin >> tmp;
q.push({ i,tmp });
pq.push(tmp);
}
while (!q.empty())
{
int index = q.front().first;
int priority = q.front().second;
q.pop();
if (pq.top() == priority) // 값 비교
{
pq.pop();
answer++;
if (index == m) // 인덱스 비교
{
break;
}
}
else
{
q.push({ index,priority });
}
}
cout << answer << endl;
}
return 0;
}