P28199 [洛谷] [National Training Team] Planting Trees
提高
题目描述

Problem Description

City A has a large circular plaza. To green the environment and purify the air, the municipal government has decided to plant a ring of trees along the outer circumference of the circular plaza.

After receiving the directive, the landscaping department has initially planned out \( n \) planting positions, numbered clockwise from 1 to \( n \). Each position has an aesthetic value \( A_i \), and planting a tree there would yield this aesthetic value \( A_i \). However, due to the poor soil fertility in City A, two trees cannot be planted in adjacent positions (position \( i \) and position \( i+1 \) are considered adjacent. Notably, positions 1 and \( n \) are also adjacent).

The municipal government has provided the landscaping department with \( m \) tree seedlings and requires that all of them be planted. Please help design a planting scheme to maximize the total aesthetic value. If it is not possible to plant all \( m \) tree seedlings, output an error message.

Input Format

The first line of input contains two positive integers \( n \) and \( m \).

The second line contains \( n \) integers, where the \( i \)-th integer represents \( A_i \).

Output Format

Output a single integer, which is the maximum aesthetic value that can be achieved with the optimal planting scheme. If it is not possible to plant all \( m \) tree seedlings, output Error!.

Sample Input and Output

Sample Input #1

7 3
1 2 3 4 5 6 7

Sample Output #1

15

Sample Input #2

7 4
1 2 3 4 5 6 7

Sample Output #2

Error!

Notes

Data ID Size of \( n \) Data ID Size of \( n \)
1 30 11 200
2 35 12 2007
3 40 13 2008
4 45 14 2009
5 50 15 2010
6 55 16 2011
7 60 17 2012
8 65 18 199999
9 200 19 199999
10 200 20 200000

For all data: \( m \leq n \), \( -1000 \leq A_i \leq 1000 \).

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
7 3 1 2 3 4 5 6 7
样例输出
15