#C5824. Maximum Sum Subarray of Fixed Length

    ID: 49516 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 compute the maximum sum of any contiguous subarray of length K. In other words, you need to find the maximum value of

$$ S = \max_{0 \leq i \leq N-K} \sum_{j=i}^{i+K-1} arr[j] $$

Use an efficient algorithm such as the sliding window technique to solve this problem in linear time.

inputFormat

The first line of input contains two integers N and K separated by a space. The second line contains N integers representing the array elements, separated by spaces.

Constraints: 1 ≤ K ≤ N ≤ 105. The absolute value of each element is within reasonable limits.

outputFormat

Output a single integer that denotes the maximum possible sum of any contiguous subarray of length K.

## sample
6 3
1 2 3 4 5 6
15