티스토리 뷰

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
#include <iostream>
#include <queue>
using namespace std;
 
int main()
{
    int test_case;
    cin >> test_case;
    for (size_t i = 0; i < test_case; i++) {
        int N, position;
        cin >> N >> position;
        queue<pair<intint>> que;
        priority_queue<int> priq;
        for (size_t j = 0; j < N; j++) {
            int priority;
            cin >> priority;
            que.push({ j, priority });
            priq.push(priority);
        }
        int count = 0;
        while (!que.empty()) {
            int idx = que.front().first;
            int priority = que.front().second;
            que.pop();
            if (priq.top() == priority) {
                count++;
                priq.pop();
                if (idx == position)
                    break;
            }
            else
                que.push({ idx, priority });
        }
        cout << count << endl;
    }
    return 0;
}
cs
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/12   »
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
글 보관함