#K14651. Maximum Sum of K Consecutive Rainfall Volumes

    ID: 24182 Type: Default 1000ms 256MiB

Maximum Sum of K Consecutive Rainfall Volumes

Maximum Sum of K Consecutive Rainfall Volumes

You are given the rainfall volumes for n consecutive days and an integer k. Your task is to determine the maximum possible sum of rainfall over any contiguous subarray of k days.

The sum for a subarray starting at day i is given by the formula:

\( S = \sum_{j=i}^{i+k-1} a_j \)

where \(a_j\) represents the rainfall volume on the jth day.

You are expected to use an efficient sliding window technique to solve this problem.

inputFormat

The first line contains two space-separated integers n and k, where n is the number of days and k is the size of the window.

The second line contains n space-separated integers representing the rainfall volumes for each day.

outputFormat

Output a single integer representing the maximum sum of rainfall volumes over any contiguous subarray of k days.

## sample
5 2
1 2 3 4 5
9