#P3009. Maximum Consecutive Profit

    ID: 16267 Type: Default 1000ms 256MiB

Maximum Consecutive Profit

Maximum Consecutive Profit

The cows have opened a new business and recorded their net profit over N days. On day i, the net profit is given by \(P_i\) where \( -1000 \leq P_i \leq 1000 \) and \( 1 \leq N \leq 100000 \). Farmer John is interested in finding the maximum total profit over any consecutive days (from a single day up to all \(N\) days).

Your task is to compute the maximum sum of any contiguous subarray of these profits. This is a classic maximum subarray problem that can efficiently be solved using Kadane's algorithm.

inputFormat

The input consists of two lines. The first line contains an integer \(N\), representing the number of days. The second line contains \(N\) space-separated integers representing the net profit \(P_i\) for each day.

outputFormat

Output a single integer, the maximum sum of profits for any consecutive time period.

sample

5
1 -2 3 4 -1
7