Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. pair<int,int> minmax(int t[], int n)
  6. {
  7. if (n==1) return make_pair(t[0],t[0]);
  8. int p =n/2;
  9. pair<int,int> lewy = minmax(t,p);
  10. pair<int,int> prawy = minmax(t+p,n-p);
  11. return make_pair(min(lewy.first, prawy.first), max(lewy.second, prawy.second));
  12. }
  13.  
  14. int main()
  15. {
  16. int n;
  17. cin >> n;
  18. int tab[n];
  19. for (int i=0;i<n;i++)
  20. cin >> tab[i];
  21. pair<int,int> wynik = minmax(tab,n);
  22. cout << wynik.first << ' ' << wynik.second << endl;
  23.  
  24.  
  25. return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement