performance improvement for max subarray