#C3509. Max Candies with Consecutive House Constraint
Max Candies with Consecutive House Constraint
Max Candies with Consecutive House Constraint
You are given N houses, and each house has a certain number of candies. Your task is to determine the maximum number of candies you can collect by choosing a contiguous segment of houses. Formally, if the candy counts are given by an array \(a_1, a_2, \dots, a_N\), you should find the maximum value of
\(\max_{1 \le i \le j \le N} \left(\sum_{k=i}^{j} a_k\right)\)
Note that the problem statement mentions a constraint about collecting from at most one pair of consecutive houses, but in essence you are to determine the maximum contiguous subarray sum.
inputFormat
The input is given via stdin and consists of two lines:
- The first line contains an integer \(N\) \((1 \le N \le 10^5)\), the number of houses.
- The second line contains \(N\) space-separated integers representing the number of candies at each house.
outputFormat
Output a single integer to stdout representing the maximum number of candies that can be collected.
## sample1
5
5