#P6821. [PA 2012] Tanie linie

[PA 2012] Tanie linie

Description

Given a sequence containing nn numbers, find the maximum possible sum of at most kk non-overlapping subarrays.

Input Format

The first line contains two positive integers n,kn, k.

The next line contains nn integers, which form the sequence.

Output Format

Output one integer, the answer.

5 2
7 -3 4 -9 5
13

Hint

For 100%100\% of the testdata, 1kn1061 \le k \le n \le 10^6. All numbers in the sequence are within [109,109][-10^9, 10^9].

Translated by ChatGPT 5