-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1966.cpp
More file actions
49 lines (39 loc) · 1012 Bytes
/
1966.cpp
File metadata and controls
49 lines (39 loc) · 1012 Bytes
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
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
using namespace std;
int T,N,M,ans;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin >> T;
while(T--){
cin >> N >> M;
queue<pair<int,int>> q;
vector<int> imp;
for(int i=0 ; i<N ; i++){
int importance;
cin >> importance;
imp.push_back(importance);
q.push({i,importance});
}
sort(imp.begin(), imp.end(), greater<int>());
int idx=0, cnt = 0;
while(!q.empty()) {
if(q.front().second == imp[idx]){
cnt++; idx++;
if(q.front().first == M){
cout << cnt << '\n';
break;
}
q.pop();
}else{
pair<int,int> a = q.front();
q.pop();
q.push(a);
}
}
}
}