#C9308. Maximum Sum of Consecutive Numbers
Maximum Sum of Consecutive Numbers
Maximum Sum of Consecutive Numbers
Given a list of integers and an integer \(k\), compute the maximum sum of any \(k\) consecutive elements in the list. The sum of \(k\) consecutive numbers is given by \(\sum_{i=0}^{k-1} a_{i}\). If the list contains fewer than \(k\) elements, output 0.
inputFormat
The input is read from standard input (stdin).
Format:
1. The first line contains an integer (n) representing the number of elements.
2. The second line contains (n) space-separated integers.
3. The third line contains an integer (k) indicating the number of consecutive elements to consider.
outputFormat
Output a single integer to standard output (stdout), which is the maximum sum of any (k) consecutive elements in the list. If there are fewer than (k) elements, output 0.## sample
9
1 4 2 10 23 3 1 0 20
4
39