Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- ios::sync_with_stdio(0); cin.tie(0);
- int t;
- cin>>t;
- while(t--)
- {
- int n, m;
- cin>>n>>m;
- queue < pair <int, int> > Q; // Q.first = priority, Q.second = index
- priority_queue <int> PQ;
- for(int i = 0; i < n; i++)
- {
- int p;
- cin>>p;
- Q.push({p, i});
- PQ.push(p);
- }
- int time = 1;
- while(1)
- {
- pair <int,int> F = Q.front();
- if(F.first < PQ.top())
- {
- Q.pop();
- Q.push(F);
- }
- else
- {
- if(F.second == m)
- {
- cout<<time<<"\n";
- break;
- }
- else
- {
- time++;
- Q.pop();
- PQ.pop();
- }
- }
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment