#P1714. Maximum Lucky Cake Sum

    ID: 14999 Type: Default 1000ms 256MiB

Maximum Lucky Cake Sum

Maximum Lucky Cake Sum

Today is the birthday of little Z. His classmates have brought him a rectangular cake which has been divided into n identical pieces, each with a lucky value. Since little Z can only eat at most m pieces of cake, he wants to choose a contiguous segment of the cake (of length k where \(1 \le k \le m\)) so that the sum of its lucky values is maximized.

Formally, given a sequence \(\{p_i\}_{i=1}^{n}\), find a subarray \([l, r]\) with \(r-l+1 \le m\) that maximizes \(\sum_{i=l}^{r}p_i\).

It is possible that some lucky values are negative, so choosing a single piece could be optimal.

inputFormat

The input consists of two lines. The first line contains two space-separated integers \(n\) and \(m\) where \(1 \le m \le n\). The second line contains \(n\) space-separated integers \(p_1, p_2, \ldots, p_n\), representing the lucky values of the cake pieces.

outputFormat

Output a single integer, the maximum possible sum of a contiguous segment of the cake pieces with length at most \(m\).

sample

5 3
1 2 3 4 5
12

</p>