Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. using pii = pair<int, int>;
  5.  
  6. pii mxmn(int *a, int l, int r) {
  7. if (r-l+1 <= 1) return pii(a[l], a[r]);
  8. int m = (l+r) / 2;
  9. pii subL = mxmn(a, l, m);
  10. pii subR = mxmn(a, m+1, r);
  11. return pii(min(subL.first, subR.first), max(subL.second, subR.second));
  12. }
  13.  
  14. int main() {
  15. int n = 4;
  16. int *a = new int[n+1] {0, 2, 55, -1, 10};
  17.  
  18. auto rlt = mxmn(a, 1, n);
  19. printf("%d %d\n", rlt.first, rlt.second);
  20.  
  21. return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement