Ankit_132

E

Nov 17th, 2023
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define ll     long long
  7. #define _test   int _TEST; cin>>_TEST; while(_TEST--)
  8.  
  9. int main()
  10. {
  11.     _test
  12.     {
  13.         int n;
  14.         cin>>n;
  15.  
  16.         vector<ll int> a(n);
  17.         for(auto &e: a)     cin>>e;
  18.  
  19.         int mmin = *min_element(a.begin(), a.end());
  20.  
  21.         int pos = -1;
  22.  
  23.         for(int i=0; i<n; i++)
  24.         {
  25.             if(a[i] == mmin)
  26.             {
  27.                 pos = i;
  28.                 break;
  29.             }
  30.         }
  31.  
  32.         if(pos==n-1 || is_sorted(a.begin()+pos, a.end()))
  33.             cout<<pos<<"\n";
  34.         else
  35.             cout<<-1<<"\n";
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment