Maximum Window Sum
View as PDFGiven an array of length
and an integer
, find the maximum possible sum of a
contiguous subarray of length exactly
.
Remember that a subarray is a contiguous section of the array.
Input
The first line contains two integers and
.
The second line contains integers
.
Output
Print a single integer: the maximum sum of any contiguous subarray of length exactly .
Constraints
Example 1
Input
5 3
1 -2 3 -4 5
Output
4
Explanation
The length- subarrays have sums
,
, and
, so the answer is
.
Example 2
Input
8 3
-512 750 27 -532 -940 781 -449 278
Output
610
Comments