-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1966.cpp
More file actions
45 lines (41 loc) · 922 Bytes
/
1966.cpp
File metadata and controls
45 lines (41 loc) · 922 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
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#define io ios::sync_with_stdio(false); cin.tie(0);
using namespace std;
int main()
{
io;
int T,N,M;
cin>>T;
for(int t=0;t<T;t++){
cin>>N>>M;
int v,count=0;
queue<int> doc;
vector<int> seq(N);
for(int i=0;i<N;i++){
cin>>v;
doc.push(v);
seq[i]=v;
}
sort(seq.begin(),seq.end(),greater<int>());
int i=0;
while(i<N){
if(seq[i]==doc.front()){
count++;
if(M==0) break;
doc.pop();
i++;
}else{
int temp=doc.front();
doc.pop();
doc.push(temp);
}
if(M>0) M--;
else if(M==0) M=doc.size()-1;
}
cout<<count<<'\n';
}
return 0;
}