#P1484. 种树

种树

Description

cyrcyr is planting trees today. He dug nn pits on a straight line. Each of these nn pits can be used to plant a tree, but to ensure every tree has sufficient nutrients, cyrcyr will not plant trees in two adjacent pits. Also, because cyrcyr does not have enough saplings, he will plant at most kk trees. Assuming cyrcyr has a special ability to foresee the profit from planting a tree in any pit (which may be negative), please help him compute his maximum total profit.

Input Format

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

The second line contains nn integers. The ii-th number denotes the profit from planting a tree in the ii-th pit from left to right on the line.

Output Format

Output a single number, the maximum profit that cyrcyr can obtain.

6 3 
100 1 -1 100 1 -1

200

Hint

For 20%20\% of the testdata, n20n \leq 20.

For 50%50\% of the testdata, n6000n \leq 6000.

For 100%100\% of the testdata, 1n3000001 \le n \le 300000, 1kn21 \le k \le \dfrac{n}{2}, and the absolute value of the profit at any single position is at most 10610^6.

Translated by ChatGPT 5