Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std ;
- #define sz(s) int(s.size())
- #define all(v) v.begin() , v.end()
- #define imin INT_MIN
- #define imax INT_MAX
- typedef long long ll ;
- #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" << "\n";
- #define all(s) s.begin(), s.end()
- void ABDEL3AL () {
- ios_base::sync_with_stdio(false); cin.tie(nullptr) , cout.tie(nullptr) ;
- #ifndef ONLINE_JUDGE
- freopen("input.txt" , "r" , stdin) , freopen("output.txt" , "w" , stdout) ;
- #endif
- Time
- }
- int main() {
- ABDEL3AL() ;
- int t ; cin >> t ;
- int Mx = imin, Mn = imax ;
- int idxmin = 0, idxmax = 0, move_1 = 0, move_2 = 0, move_3 = 0 ;
- while (t--) {
- int n ; cin >> n ;
- vector < int > vec(n) ;
- for (int i = 0; i < n; i++) {
- cin >> vec[i] ;
- if (vec[i] < Mn) Mn = vec[i] , idxmin = i ;
- if (vec[i] > Mx) Mx = vec[i] , idxmax = i ;
- }
- int size = n ;
- move_1 = size - min(idxmin , idxmax) ;
- move_2 = max(idxmax , idxmin) + 1 ;
- move_3 = size - min(idxmin ,idxmax) + 1 + max(idxmax , idxmin) ;
- cout << min({move_1 , move_2 , move_3}) << "\n" ;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement