#P1714. 切蛋糕

切蛋糕

Description

Today is Xiao Z's birthday, and his classmates brought him a cake. The cake is a rectangular prism, divided into nn identical small pieces with different colors, and each small piece has a corresponding lucky value.

As the birthday person, Xiao Z naturally wants the sum of lucky values of the cake he eats to be as large as possible, but Xiao Z can eat at most m(mn)m(m\le n) small pieces of cake.

Please help him choose k(1km)k(1 \le k\le m) consecutive pieces among these nn pieces so that their total lucky value is maximized.

Formally, in the sequence {pn}\{p_n\}, find a subsegment [l,r](rl+1m)[l,r](r-l+1\le m) that maximizes i=lrpi\sum\limits_{i=l}^rp_i.

Input Format

The first line contains two integers n,mn,m. They represent that there are nn small pieces in total, and Xiao Z can eat at most mm small pieces.

The second line contains nn integers. The ii-th integer pip_i represents the lucky value of the ii-th small piece of cake.

Output Format

Output a single integer in one line, which is the maximum lucky value Xiao Z can obtain.

5 2
1 2 3 4 5
9
6 3
1 -2 3 -4 5 -6
5

Hint

Constraints and Conventions.

  • For 20%20\% of the testdata, 1n1001\le n\le100.
  • For 100%100\% of the testdata, 1n5×1051\le n\le5\times 10^5, pi500|p_i|≤500.

It is guaranteed that the absolute value of the answer is within [0,2311][0,2^{31}-1].

Translated by ChatGPT 5