#C4244. Maximum Products Processed

    ID: 47761 Type: Default 1000ms 256MiB

Maximum Products Processed

Maximum Products Processed

You are given an integer n representing the number of days and an array of n integers. Each integer in the array represents the number of products processed on a specific day, and the value may be negative, indicating a loss. Your task is to determine the maximum total number of products that can be processed in any contiguous sequence of days.

This problem is a classic instance of the Maximum Subarray Problem which can be efficiently solved using Kadane's algorithm. In mathematical terms, if the array is \(a_1, a_2, \ldots, a_n\), find the maximum sum of any contiguous subarray \(\max_{1 \leq i \leq j \leq n} \sum_{k=i}^{j} a_k\).

inputFormat

The first line of input contains an integer n denoting the number of days. The second line contains n space-separated integers, where each integer represents the number of products processed on that day.

outputFormat

Output a single integer which is the maximum sum of a contiguous subarray from the given list.## sample

5
1 -2 3 4 -1
7

</p>