Guest User

Untitled

a guest
Jul 4th, 2017
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     ios::sync_with_stdio(0); cin.tie(0);
  7.     int t;
  8.     cin>>t;
  9.     while(t--)
  10.     {
  11.         int n, m;
  12.         cin>>n>>m;
  13.  
  14.         queue < pair <int, int> > Q;        // Q.first = priority, Q.second = index
  15.         priority_queue <int> PQ;
  16.  
  17.         for(int i = 0; i < n; i++)
  18.         {
  19.             int p;
  20.             cin>>p;
  21.             Q.push({p, i});
  22.             PQ.push(p);
  23.         }
  24.  
  25.         int time = 1;
  26.         while(1)
  27.         {
  28.             pair <int,int> F = Q.front();
  29.             if(F.first < PQ.top())
  30.             {
  31.                 Q.pop();
  32.                 Q.push(F);
  33.             }
  34.             else
  35.             {
  36.                 if(F.second == m)
  37.                 {
  38.                     cout<<time<<"\n";
  39.                     break;
  40.                 }
  41.                 else
  42.                 {
  43.                     time++;
  44.                     Q.pop();
  45.                     PQ.pop();
  46.                 }
  47.             }
  48.         }
  49.     }
  50.     return 0;
  51. }
Add Comment
Please, Sign In to add comment