#P10478. 生日礼物

生日礼物

Problem Description

On ftiasch's 18th birthday, lqp18_31 showed her a magical sequence A1A_1, A2A_2, ..., ANA_N. She is allowed to choose at most MM consecutive segments as her birthday gift.

Naturally, ftiasch wants to know the maximum possible sum of the selected elements. Can you help her?

Input Format

Line 1: Two integers NN (1N1051 \le N \le 10^5) and MM (0M1050 \le M \le 10^5), representing the length of the sequence and the number of segments that can be chosen.

Line 2: NN integers A1A_1, A2A_2, ..., ANA_N (0Ai1040 \le \mid A_i \mid \le 10^4), representing the sequence.

Output Format

One integer, representing the maximum sum.

5 2
2 1 -2 3 -2
6

Hint

Translated by ChatGPT 5