Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using pii = pair<int, int>;
- pii mxmn(int *a, int l, int r) {
- if (r-l+1 <= 1) return pii(a[l], a[r]);
- int m = (l+r) / 2;
- pii subL = mxmn(a, l, m);
- pii subR = mxmn(a, m+1, r);
- return pii(min(subL.first, subR.first), max(subL.second, subR.second));
- }
- int main() {
- int n = 4;
- int *a = new int[n+1] {0, 2, 55, -1, 10};
- auto rlt = mxmn(a, 1, n);
- printf("%d %d\n", rlt.first, rlt.second);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement