bhushan23

PQueueSPOJ

Aug 6th, 2013
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.90 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int t,i,j;
  7. cin >>t;
  8. while(t--)
  9. {
  10.           int n,m,cnt;
  11.           cin >> n ;
  12.           cin >> m;
  13.          int VISITED[n],arr[n];
  14.          
  15.           for(i=0;i<n;i++)
  16.           {
  17.           cin>>arr[i];
  18.           VISITED[i]=-1;
  19.           }
  20.           int cur=0,max,max_ind;
  21.           cnt=0;
  22.           while(VISITED[m]!=1)
  23.           {
  24.           cnt++;
  25.          
  26.           max=0;
  27.           for(int i=0;i<n;i++)
  28.           {
  29.           j=(cur+i)%n;
  30.           if(VISITED[j] ==-1&& max < arr[j])
  31.                     {
  32.                     max=arr[j];
  33.                     max_ind=j;
  34.                    
  35.                     }
  36.           }
  37.           cur=max_ind;
  38.           VISITED[max_ind]=1;
  39.           //cout<<"\n..cur "<<cur<<" visited "<< arr[cur];
  40.           }
  41.          
  42.          
  43.             cout<<cnt<<"\n";
  44.           }
  45.        
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment