-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1966.cpp
62 lines (56 loc) · 1.25 KB
/
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
56
57
58
59
60
61
62
//
// Created by vkdne on 2018-03-13.
//
#include <iostream>
#include <queue>
using namespace std;
int main(){
int T;
cin >> T;
int N, M;
int a;
while(T--){
queue<int> q;
priority_queue<int> pq;
cin >> N >> M;
//int max = -1;
int sol = 0;
for(int i = 0; i < N ; i++){
cin >> a;
q.push(a);
pq.push(a);
}
int tmp;
int idx = M;
while(1) {
//대상물 전까지 push, pop
for (int i = 0; i < idx; i++) {
if (q.front() == pq.top()) {
q.pop();
pq.pop();
sol++;
}
else {
tmp = q.front();
q.pop();
q.push(tmp);
}
}
//대상물 push or pop
if (q.front() == pq.top()) {
q.pop();
pq.pop();
sol++;
cout <<sol<<endl;
break;
}
else{
tmp = q.front();
q.pop();
q.push(tmp);
idx = q.size() - 1;
}
}
}
return 0;
}