#C14638. Maximum Sum of Subarray of Fixed Length

    ID: 44309 Type: Default 1000ms 256MiB

Maximum Sum of Subarray of Fixed Length

Maximum Sum of Subarray of Fixed Length

You are given an array of n integers and an integer k. Your task is to find the maximum sum of any contiguous subarray of length k.

Formally, let the array be \(a_1, a_2, \dots, a_n\). You need to compute:

\(\max_{1 \leq i \leq n-k+1} \sum_{j=i}^{i+k-1} a_j\)

If k is less than or equal to zero, greater than n, or if the array is empty, the answer is defined to be 0.

The input is read from standard input (stdin) and the result should be printed to standard output (stdout).

inputFormat

The first line of input contains two integers n and k, where n represents the number of elements in the array, and k is the length of the subarray.

The second line contains n space-separated integers representing the array elements.

If n is 0, the second line may be empty.

outputFormat

Output a single integer, the maximum sum of any contiguous subarray of length k. If no valid subarray exists, output 0.

## sample
5 2
1 2 3 4 5
9

</p>