-
Notifications
You must be signed in to change notification settings - Fork 0
/
PrinterQueue.cpp
53 lines (47 loc) · 1.06 KB
/
PrinterQueue.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
/* https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3252
* #priority-queue #queue
*/
#include<queue>
#include<iostream>
#include<vector>
using namespace std;
class Node {
public:
int val;
int idx;
Node(int _val, int _idx) {
this->val = _val;
this->idx = _idx;
}
};
int main() {
int testcases;
cin >> testcases;
for(int i=0; i < testcases; i++) {
int n, m;
cin >> n >> m;
priority_queue<int> pq;
queue<Node> q;
for (int j=0; j < n; j++) {
int tmp;
cin >> tmp;
q.push(Node(tmp, j));
pq.push(tmp);
}
int count = 0;
while (!q.empty()) {
Node node = q.front();
q.pop();
if(node.val == pq.top()) {
pq.pop();
count++;
if(node.idx == m) {
break;
}
} else {
q.push(node);
}
}
cout << count << endl;
}
}