int maxCrossingSum(const vector<int>& arr, int left, int mid, int right) {
int leftSum = INT_MIN, rightSum = INT_MIN; int sum = 0;
for (int i = mid; i >= left; i--) {
sum += arr[i];
leftSum = max(leftSum, sum);
}
sum = 0;
for (int i = mid + 1; i <= right; i++) {
sum += arr[i];
rightSum = max(rightSum, sum);
}
return leftSum + rightSum;
}
int maxSubArraySum(const vector<int>& arr, int left, int right) {
if (left == right) return arr[left];
int mid = (left + right) / 2;
return max({maxSubArraySum(arr, left, mid), maxSubArraySum(arr, mid + 1, right),
maxCrossingSum(arr, left, mid, right)});
}