#K67047. Maximum Subarray Sum
Maximum Subarray Sum
Maximum Subarray Sum
Given an array of integers, the task is to find the maximum sum of any contiguous subarray. Formally, given an integer \(N\) and an array \(Z\) of \(N\) integers, you need to compute
\[
\text{max extunderscore subarray\_sum} = \max_{1 \leq i \leq j \leq N} \sum_{k=i}^{j} Z[k],
\]
where the subarray is defined by the start index \(i\) and the end index \(j\). This problem can be efficiently solved using Kadane's algorithm.
Example:
For \(N = 5\) and \(Z = [1, -2, 3, 4, -1]\), the maximum subarray sum is 7
(from subarray \([3, 4])\).
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains an integer \(N\), the number of elements in the array.
- The second line contains \(N\) space-separated integers representing the elements of the array \(Z\).
outputFormat
Output to standard output (stdout) a single integer representing the maximum sum of any contiguous subarray of \(Z\).
## sample5
1 -2 3 4 -1
7