POJ_3125_Printer Queue

#include<iostream> #include<queue> using namespace std; int main() { int t, n, m, x; cin>>t; while(t--) { cin>>n>>m; queue<int>q; priority_queue<int>v; for(int i=0; i<n; i++) { cin>>x; q.push(x); v.push(x); } while(1) { x=q.front(); q.pop(); if(m==0) { if(x!=v.top()) { m=v.size()-1; q.push(x); } else break; } else { m--; if(x!=v.top()) q.push(x); else v.pop(); } } cout<<n-q.size()<<endl; } return 0; } 

你可能感兴趣的:(POJ_3125_Printer Queue)