#C14979. Maximum Consecutive Sum
Maximum Consecutive Sum
Maximum Consecutive Sum
You are given a list of integers and an integer \(k\). Your task is to compute the maximum sum of any \(k\) consecutive elements in the list. If \(k\) is greater than the number of elements in the list, is less than or equal to zero, or if the list is empty, you should output \(0\).
For example, given the list [1, 2, 3, 4, 5] and \(k = 2\), the maximum sum is \(9\) (i.e. \(4 + 5 = 9\)).
Note: Input is given via standard input and output should be printed to standard output.
inputFormat
The input consists of two lines:
- The first line contains two integers \(n\) and \(k\), where \(n\) is the number of elements in the list and \(k\) is the number of consecutive elements to sum.
- The second line contains \(n\) integers separated by spaces, representing the elements of the list. If \(n = 0\), the second line will be empty.
outputFormat
Output a single integer which is the maximum sum of any \(k\) consecutive elements in the list. If a valid subarray cannot be formed based on the conditions, output \(0\).
## sample5 2
1 2 3 4 5
9