Maximum Window Sum
Given an array a of length n and an integer k, find the maximum possible sum of a contiguous subarray of length exactly k.
Remember that a subarray is a contiguous section of the array.
Input
The first line contains two integers n and k.
The second line contains n integers a1,a2,…,an.
Output
Print a single integer: the maximum sum of any contiguous subarray of length exactly k.
Constraints
- 1≤k≤n≤105
- −103≤ai≤103
Example 1
5 3
1 -2 3 -4 5
4
Explanation
The length-3 subarrays have sums 2, −3, and 4, so the answer is 4.
Example 2
8 3
-512 750 27 -532 -940 781 -449 278
610
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.