#include<iostream>
#include<vector>
#include<string>
#include<type_traits>
#include<sstream>
#include<tuple>
#include<bitset>
#include<regex>
#include<set>
#include<queue>
#include<map>
using namespace std;
int main(){
int T;
cin >> T;
int n, m;
while (T--){
cin >> n >> m;
priority_queue<int> pq;
queue<int> q;
int a;
for (int i = 0; i < n; i++){
cin >> a;
pq.push(a);
q.push(a);
}
int cur = 0;
while (true){
if (pq.top() == q.front()){
if (cur == m){
cout << n - q.size() + 1 << endl;
break;
}
else{
pq.pop();
q.pop();
cur++;
}
}
else{
int a = q.front();
q.pop();
q.push(a);
if (cur == m){
cur = 0;
m = q.size() - 1;
}
else{
cur++;
}
}
}
}
//system("pause");
return 0;
}
UVA 12100
最新推荐文章于 2021-04-12 19:46:03 发布