Ankit_132

B - Minimize Permutation Subarrays

Jun 4th, 2023
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 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. #define pb     push_back
  9. #define ppb    pop_back
  10.  
  11. int main()
  12. {
  13.     _test
  14.     {
  15.         int n;
  16.         cin>>n;
  17.  
  18.         vector<ll int> a(n);
  19.         for(auto &e: a)
  20.             cin>>e;
  21.  
  22.         int pos1, pos2, posn;
  23.  
  24.         for(int i=0; i<n; i++)
  25.         {
  26.             if(a[i]==1)     pos1 = i;
  27.             if(a[i]==2)     pos2 = i;
  28.             if(a[i]==n)     posn = i;
  29.         }
  30.  
  31.         if((pos1<posn && posn<pos2) || (pos1>posn && posn>pos2))
  32.             cout<<pos1+1<<" "<<pos1+1<<"\n";
  33.         else if((pos1<pos2 && pos2<posn) || (pos1>pos2 && pos2>posn))
  34.             cout<<pos2+1<<" "<<posn+1<<"\n";
  35.         else
  36.             cout<<pos1+1<<" "<<posn+1<<"\n";
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment