#C11828. Maximum Shade Contiguous Subarray Sum

    ID: 41187 Type: Default 1000ms 256MiB

Maximum Shade Contiguous Subarray Sum

Maximum Shade Contiguous Subarray Sum

You are given a sequence of n integers representing the amount of shade at each position along a railway track. Your task is to compute the maximum possible sum from any contiguous subarray of length k.

More formally, given an array \(a_1, a_2, \ldots, a_n\) and an integer \(k\) (with \(1 \le k \le n\)), you need to find the maximum sum of a subarray of exactly \(k\) consecutive elements.

Example: For input array [1, 2, 3, 4, 5, 6, 7, 8] with \(k=3\), the maximum sum is \(6+7+8=21\).

inputFormat

The first line contains two space-separated integers, \(n\) and \(k\), where \(n\) represents the number of positions, and \(k\) is the length of the contiguous subarray to consider. The second line contains \(n\) space-separated integers, representing the shade at each position.

outputFormat

Output a single integer representing the maximum sum of any contiguous subarray of length \(k\>.

## sample
8 3
1 2 3 4 5 6 7 8
21

</p>