#K75047. Maximum Sum Subarray of Fixed Length

    ID: 34332 Type: Default 1000ms 256MiB

Maximum Sum Subarray of Fixed Length

Maximum Sum Subarray of Fixed Length

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

The problem can be formulated as follows:

$$\max_{0 \leq i \leq n-k} \left( \sum_{j=i}^{i+k-1} arr[j] \right)$$

Efficiently compute this sum using a sliding window approach.

inputFormat

The first line contains two space-separated integers: n and k, where n is 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 elements of the array.

outputFormat

Output a single integer, which is the maximum sum of any contiguous subarray of length k.

## sample
10 3
1 2 3 4 5 6 7 8 9 10
27