-
Notifications
You must be signed in to change notification settings - Fork 0
/
1966.cpp
52 lines (42 loc) · 965 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
#include <iostream>
#include <queue>
using namespace std;
struct card {
int val;
int idx;
};
int main() {
int total, n, m, turn;
struct card input;
queue<struct card> q;
priority_queue<int, vector<int>, less<int>> pq;
cin >> total;
for(int i=0; i<total; i++){
cin >> n;
cin >> m;
turn = 0;
while(!pq.empty())
pq.pop();
while(!q.empty())
q.pop();
for (int j=0; j<n; j++) {
cin >> input.val;
input.idx = j;
q.push(input);
pq.push(input.val);
}
while(!q.empty()) {
struct card data = q.front();
if (data.val == pq.top()) {
if (data.idx == m)
break;
pq.pop();
turn++;
}
else
q.push(data);
q.pop();
}
cout << turn+1 << endl;
}
}