-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy path[02]_2.cpp
More file actions
42 lines (35 loc) · 759 Bytes
/
[02]_2.cpp
File metadata and controls
42 lines (35 loc) · 759 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
#include <bits/stdc++.h>
using namespace std;
int tc, n, m, cnt;
int main() {
cin >> tc;
for (int i = 0; i < tc; i++) {
queue<pair<int, int>> q;
priority_queue<int> pq; // 높은 중요도부터 처리
cnt = 0;
cin >> n >> m;
for (int j = 0; j < n; j++) {
int x;
cin >> x;
q.push({x, j}); // {중요도, 인덱스} 삽입
pq.push(x); // 중요도 삽입
}
while (true) {
int x = q.front().first;
int index = q.front().second;
q.pop();
// 가장 중요도가 높은 경우 출력
if (x == pq.top()) {
cnt++;
pq.pop();
if (index == m) {
cout << cnt << '\n';
break;
}
}
else {
q.push({x, index});
}
}
}
}