Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int t,i,j;
- cin >>t;
- while(t--)
- {
- int n,m,cnt;
- cin >> n ;
- cin >> m;
- int VISITED[n],arr[n];
- for(i=0;i<n;i++)
- {
- cin>>arr[i];
- VISITED[i]=-1;
- }
- int cur=0,max,max_ind;
- cnt=0;
- while(VISITED[m]!=1)
- {
- cnt++;
- max=0;
- for(int i=0;i<n;i++)
- {
- j=(cur+i)%n;
- if(VISITED[j] ==-1&& max < arr[j])
- {
- max=arr[j];
- max_ind=j;
- }
- }
- cur=max_ind;
- VISITED[max_ind]=1;
- //cout<<"\n..cur "<<cur<<" visited "<< arr[cur];
- }
- cout<<cnt<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment