Problems > Best Window of Size K

Best Window of Size K

Difficulty: 1200 3000 ms 128 MB

sliding-window

Among all contiguous windows of exactly K elements, print the maximum window sum.

Input: the first line has N and K; the second line has N integers.

Output: the maximum sum over windows of size K.

Constraints:

  • 1 ≤ K ≤ N ≤ 105
  • −109 ≤ ai ≤ 109

Sample Tests

Input 1
6 3
2 1 5 1 3 2
Output 1
9
Input 2
2 2
-5 -2
Output 2
-7

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.