Step 12 of 12 · Sliding windows

Maximum window sum

IntermediateJavaScript1,000 ms

Problem

Read a list of whole numbers and a window size k. Return the largest sum among all contiguous groups of exactly k values.

Input

The first line contains n and k. The second line contains n space-separated integers, where 1 ≤ k ≤ n.

Output

One integer: the largest sum of any contiguous window of size k.

Examples

Input
6 3
2 1 5 1 3 2
Output
9

The window 5 1 3 has the largest sum, 9.

Input
4 2
-5 -2 -8 -1
Output
-7

The first two values form the least-negative window sum.

Browser-isolated runner

Write your solution.

Define solve(input) and return the exact output. Network access is blocked and the runner stops after 1,000 ms. Run the example to inspect local console.log output.

Best verdictNot submitted
solution.jsLocal only
Keyboard: Tab to Run, then EnterSign in to submit
Try your own inputRuns locally without adding a saved attempt
Ready

You can run the example now. Sign in to submit and save progress.

Sign in to save this work. Your code, attempts, and Accepted progress return with your account.

Saved attempts

Verdict history

No saved submissions yet. Your first verdict will appear here.