Advertisement
MohamedAbdel3al

A. Stone Game

Sep 25th, 2021
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std ;
  4. #define sz(s) int(s.size())
  5. #define all(v) v.begin() , v.end()
  6. #define imin INT_MIN
  7. #define imax INT_MAX
  8. typedef long long ll ;
  9. #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" << "\n";
  10. #define all(s) s.begin(), s.end()
  11.  
  12. void ABDEL3AL () {
  13. ios_base::sync_with_stdio(false); cin.tie(nullptr) , cout.tie(nullptr) ;
  14. #ifndef ONLINE_JUDGE
  15. freopen("input.txt" , "r" , stdin) , freopen("output.txt" , "w" , stdout) ;
  16. #endif
  17. Time
  18. }
  19.  
  20.  
  21. int main() {
  22. ABDEL3AL() ;
  23. int t ; cin >> t ;
  24. int Mx = imin, Mn = imax ;
  25. int idxmin = 0, idxmax = 0, move_1 = 0, move_2 = 0, move_3 = 0 ;
  26. while (t--) {
  27. int n ; cin >> n ;
  28. vector < int > vec(n) ;
  29. for (int i = 0; i < n; i++) {
  30. cin >> vec[i] ;
  31. if (vec[i] < Mn) Mn = vec[i] , idxmin = i ;
  32. if (vec[i] > Mx) Mx = vec[i] , idxmax = i ;
  33. }
  34. int size = n ;
  35. move_1 = size - min(idxmin , idxmax) ;
  36. move_2 = max(idxmax , idxmin) + 1 ;
  37. move_3 = size - min(idxmin ,idxmax) + 1 + max(idxmax , idxmin) ;
  38. cout << min({move_1 , move_2 , move_3}) << "\n" ;
  39.  
  40. }
  41. return 0;
  42. }
  43.  
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement