Maximum Sum of K Consecutive Elements
Easyjavapythonccppjavascript
Given an integer array and a number K, find the maximum sum of any contiguous subarray of exactly K elements.
Input Format
The first line contains two integers N and K. The second line contains N space-separated integers.
Output Format
Print the maximum sum of a window of K consecutive elements.
Example 1
Input
6 3 2 1 5 1 3 2
Output
9
Explanation: The window [5, 1, 3] has the maximum sum 9.
- 1 <= K <= N <= 100000
- -1000000000 <= A[i] <= 1000000000