Skip to main content
Tuesday (24.11.2026) at 20:00: ALGOR Contest: Round #4 (Special Challenge) starts!

~/algor $ cat problems/minmax-38-k-ta-qoshni-eng-katta-yigindi

Largest sum of K adjacent

Medium 1000 ms 128 MB 64%
Share

Positive integers $N$, $K$ and $N$ integers are given. Find the largest value of the sum of $K$ consecutive elements

$$A_{i} + A_{i + 1} + \ldots + A_{i + K - 1}, \qquad 1 \le i \le N - K + 1$$

Choosing the largest of the sums in a window sliding along the sequence

Input

The first line contains two positive integers: $N$ and $K$. The next line contains $N$ integers $A_{i}$.

Output

One integer.

Note

$1 \le K \le N \le 10^{5}$
$-10^{9} \le A_{i} \le 10^{9}$

Examples

Input #1
7 3
2 6 1 5 4 3 7
Output #1
14
Input #2
3 3
-1 4 -2
Output #2
1

Sign in to submit a solution

Signing up is free and takes a minute.