#C12248. Maximum and Minimum Subarray Sum

    ID: 41654 Type: Default 1000ms 256MiB

Maximum and Minimum Subarray Sum

Maximum and Minimum Subarray Sum

Given an array of integers, your task is to find two contiguous subarrays:

  • The subarray with the maximum sum together with its starting and ending indices.
  • The subarray with the minimum sum together with its starting and ending indices.

If the array is empty, output None for both cases.

This problem requires an \(O(n)\) approach, processing the array in a single pass to update both the maximum and minimum subarray sums.

inputFormat

The first line contains an integer \(n\) representing the number of elements in the array.

The second line contains \(n\) space-separated integers. If \(n=0\), the array is considered empty.

outputFormat

If the array is not empty, print two lines:

  • The first line contains three space-separated integers: the maximum subarray sum, the starting index, and the ending index.
  • The second line contains three space-separated integers: the minimum subarray sum, the starting index, and the ending index.

If the array is empty, print None on both lines.

## sample
5
1 2 3 4 5
15 0 4

1 0 0

</p>