Given an array of N integers and an integer K, find the maximum sum of any contiguous subarray of length K.
Input (read from stdin)
N K
a1 a2 a3 ... aN
1 ≤ K ≤ N ≤ 10^5-10^4 ≤ ai ≤ 10^4Output (write to stdout)
max_sum
where max_sum is the maximum possible sum of a subarray with exactly K elements.
Input
7 3
2 1 5 1 3 2 1
Output
9
Explanation
The subarray [5,1,3] has sum 9, which is the largest among all length‑3 subarrays.
Example 1
Input: 7 3 2 1 5 1 3 2 1
Output: 9
The subarray [5,1,3] yields the maximum sum 9.
Example 2
Input: 5 2 -1 -2 -3 -4 -5
Output: -3
The least negative sum is obtained from [-1,-2].
Constraints
Hints
Given an array of N integers and an integer K, find the maximum sum of any contiguous subarray of length K.
Input (read from stdin)
N K
a1 a2 a3 ... aN
1 ≤ K ≤ N ≤ 10^5-10^4 ≤ ai ≤ 10^4Output (write to stdout)
max_sum
where max_sum is the maximum possible sum of a subarray with exactly K elements.
Input
7 3
2 1 5 1 3 2 1
Output
9
Explanation
The subarray [5,1,3] has sum 9, which is the largest among all length‑3 subarrays.
Example 1
Input: 7 3 2 1 5 1 3 2 1
Output: 9
The subarray [5,1,3] yields the maximum sum 9.
Example 2
Input: 5 2 -1 -2 -3 -4 -5
Output: -3
The least negative sum is obtained from [-1,-2].
Constraints
Hints