-
Notifications
You must be signed in to change notification settings - Fork 0
/
1966프린터큐.cpp
58 lines (46 loc) · 846 Bytes
/
1966프린터큐.cpp
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
54
55
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <bits/stdc++.h>
#include <sstream>
#include <stack>
#include <queue>
using namespace std;
int N,M;
int priority;
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
priority_queue<int> pq;
queue<pair<int, int>> q;
cin >> M;
int index;
cin >> index;
for (int j = 0; j < M; j++) {
cin >> priority;
pq.push( priority );
q.push({ priority ,j});
}
int num = 1;
while (!pq.empty()) {
if (pq.top() == q.front().first) {
if (index == q.front().second) {
cout << num << "\n";
break;
}
pq.pop();
q.pop();
num++;
}
else {
int value = q.front().first;
int location = q.front().second;
q.pop();
q.push({ value,location });
}
}
}
return 0;
}