#K74237. Maximum Subarray Sum and Length
Maximum Subarray Sum and Length
Maximum Subarray Sum and Length
You are given an array of integers. Your task is to find a contiguous subarray which has the maximum sum among all possible subarrays, and also determine the length of that subarray. In the event that more than one subarray yields the same maximum sum, choose the one with the minimum length.
Note: A subarray is a continuous segment of the array.
Example:
Input: 9 -2 1 -3 4 -1 2 1 -5 4 Output: 6 4
In the above example, the subarray [4, -1, 2, 1] has the maximum sum of 6 and its length is 4.
inputFormat
The first line contains an integer n
which denotes the number of elements in the array. The second line contains n
space-separated integers representing the array.
outputFormat
Output two integers separated by a space: the maximum subarray sum and the length of the subarray that produces this sum.
## sample9
-2 1 -3 4 -1 2 1 -5 4
6 4
</p>