Solve the maximum-subarray problem again, now by divide and conquer. The best block of a[low..high] is either entirely in the left half, entirely in the right half, or crosses the middle — and the best crossing block is the best suffix of the left half plus the best prefix of the right half, found in linear time.
Write MaxSubarrayDC with crossing(a, low, mid, high) and the recursive maxSubarray(a, low, high) (mid = (low + high) / 2), counting recursive calls. Print the answer, the number of calls, and the three candidates at the top level.
For the input
8
-2 1 -3 4 -1 2 1 -5
the program prints
Maximum subarray sum: 6
Recursive calls: 15 (2n - 1 = 15)
Top level: left 4, right 3, crossing 6