#K78452. Maximum Contiguous Subarray Sum

    ID: 35089 Type: Default 1000ms 256MiB

Maximum Contiguous Subarray Sum

Maximum Contiguous Subarray Sum

You are given a sequence of integers representing the values on cards. Your task is to find the maximum sum of a contiguous subarray within this sequence. In other words, you need to identify a contiguous segment in the array such that the sum of its elements is maximized.

This problem can be efficiently solved using Kadane's Algorithm. The key recurrence in Kadane's algorithm is given by:

maxEndingHere=max(ai,maxEndingHere+ai)maxEndingHere = \max(a_i, maxEndingHere + a_i)

where ai is the i-th element of the array. The overall answer is the maximum value of maxEndingHere obtained during the iteration.

inputFormat

The first line contains an integer n representing the number of cards. The second line contains n space-separated integers representing the values on the cards.

outputFormat

Output a single integer representing the maximum sum of any contiguous subarray from the given list of card values.

## sample
5
-2 1 -3 4 -1
4