#C14648. Maximum Consecutive Revenue
Maximum Consecutive Revenue
Maximum Consecutive Revenue
You are given the daily revenue of a company for a full year. The revenue figures are provided as a list of exactly 365 integers. In addition, you are given an integer n which represents the number of consecutive days to consider. Your task is to compute the maximum total revenue generated over any consecutive n days.
The input is considered invalid if:
- The number of revenue entries is not exactly 365.
- n is less than or equal to 0 or greater than 365.
If the input is invalid, output INVALID
(without quotes). Otherwise, print the maximum total revenue over any n consecutive days.
Note: If all sliding windows are computed, at least one window will always exist for valid inputs.
inputFormat
The input consists of two lines:
- The first line contains a single integer n, the number of consecutive days.
- The second line contains 365 space-separated integers representing the revenue for each day.
outputFormat
Output a single integer representing the maximum total revenue from any consecutive n days. If the input is invalid, output INVALID
.
1
10