#C13090. Maximum Sublist Sum

    ID: 42590 Type: Default 1000ms 256MiB

Maximum Sublist Sum

Maximum Sublist Sum

You are given a list of integers. Your task is to find the maximum sum of a contiguous sublist (subarray) within the list. The list may contain both positive and negative numbers. If the list is empty, you should output 0.

This problem can be efficiently solved using Kadane's Algorithm with a time complexity of \(O(n)\). In this approach, you iterate through the list while maintaining two values: the current sublist sum and the maximum sum encountered so far.

inputFormat

The first line contains an integer \(n\) (where \(n \ge 0\)), representing the number of elements in the list. The second line contains \(n\) space-separated integers. If \(n = 0\), the second line may be omitted.

outputFormat

Output a single integer which is the maximum sum of a contiguous sublist found in the input list.

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

</p>