111. Best Window of Size K
Core1000 ms256 MBSolved by 0%
Print the largest sum of any k consecutive elements in the array.
Constraints - `1 ≤ k ≤ n ≤ 200000` - `-1000000 ≤ a[i] ≤ 1000000`
Input
The first line contains two integers n and k.
The second line contains n space-separated integers.
Output
Print one integer — the largest sum of any k consecutive elements.
Input5 2
1 4 10 2 3
Output14
Notehas its best window in the middle
Input5 5
1 2 3 4 5
Output15
Notehas a window covering the whole array
Hint 1Approach
Hint 2Approach
Hint 3Pseudocode
Hint 4Full solution