#K79142. Maximum Subarray Sum
Maximum Subarray Sum
Maximum Subarray Sum
You are given a sequence of n integers, where each integer represents the number of points obtained in a challenge. Your task is to determine the maximum sum obtainable by summing a contiguous subarray of the sequence.
The input begins with an integer n (the number of elements in the sequence), followed by n space-separated integers. You should output a single integer: the maximum contiguous subarray sum.
This problem can be solved efficiently using Kadane's algorithm. For example, given the array [1, -2, 3, 4, -1]
, the maximum subarray sum is 7
.
Note: The problem requires reading from standard input (stdin) and writing the result to standard output (stdout).
inputFormat
The first line contains an integer n, denoting the number of elements in the array. The second line contains n space-separated integers representing the points earned in each challenge.
outputFormat
Output a single integer representing the maximum sum of any contiguous subarray.
## sample5
1 -2 3 4 -1
7