POJ - 3125 Printer Queue(优先队列)
#include<iostream>
#include<queue>
using namespace std;
typedef pair<int,int> PII;
const int N = 100;
PII a[N];
int main()
{
int T;cin>>T;while(T--){
int n,m;cin>>n>>m;queue<PII> q;priority_queue<int> Q;for(int i=0;i<n;i++){
cin>>a[i].first;a[i].second=i;q.push(a[i]);Q.push(a[i].first);}int ans=0;while(1){
PII t=q.front();q.pop();if(t.first==Q.top()){
Q.pop();ans++;if(t.second==m) break;}else q.push(t);}cout<<ans<<endl;}return 0;
}