luogu#P1792. [国家集训队] 种树

    ID: 760 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP贪心线性数据结构集训队互测凸完全单调性(wqs 二分)链表

[国家集训队] 种树

Problem Description

In City A, there is a huge circular plaza. To green the environment and purify the air, the municipal government decided to plant a ring of trees along the outer edge of the circular plaza.

After receiving the order, the parks department initially planned nn planting positions, numbered clockwise from 11 to nn. Each position has an aesthetic value AiA_i, and if a tree is planted there, you gain this AiA_i value. However, due to poor soil fertility in City A, two trees must not be planted at adjacent positions (positions ii and i+1i+1 are adjacent; note that positions 11 and nn are also adjacent).

Finally, the municipal government provided the parks department with mm saplings and requires that all of them be planted. Please design a planting plan to maximize the total aesthetic value. If it is impossible to plant all mm saplings, output that there is no solution.

Input Format

The first line contains two positive integers n,mn, m.

The second line contains nn integers, where the ii-th integer represents AiA_i.

Output Format

Output one integer, the maximum total aesthetic value achievable by the optimal planting plan. If there is no solution, output Error!.

7 3
1 2 3 4 5 6 7
15
7 4
1 2 3 4 5 6 7

Error!

Hint

testdata ID nn size testdata ID nn size
11 3030 1111 200200
22 3535 1212 20072007
33 4040 1313 20082008
44 4545 1414 20092009
55 5050 1515 20102010
66 5555 1616 20112011
77 6060 1717 20122012
88 6565 1818 199999199999
99 200200 1919
1010 2020 200000200000

For all testdata: mnm \le n, 1000Ai1000-1000 \le A_i \le 1000.

Translated by ChatGPT 5