#P1792. Planting Trees in a Circular Plaza
Planting Trees in a Circular Plaza
Planting Trees in a Circular Plaza
City A has a huge circular plaza. In order to improve the environment and purify the air, the city government decided to plant a row of trees along the outer edge of the plaza. The landscaping department has planned out (n) potential positions for planting trees, numbered clockwise from 1 to (n). Each position (i) has an aesthetic value (A_i), which will be added to the total beauty if a tree is planted at that position. However, due to poor soil quality, no two trees can be planted at adjacent positions (positions (i) and (i+1) are adjacent, and note that positions 1 and (n) are also adjacent). The government has provided exactly (m) tree saplings and requires all of them to be planted. Your task is to design a planting scheme that maximizes the total aesthetic value. If it is impossible to plant all (m) trees under the given restrictions, output an appropriate message indicating that there is no solution.
inputFormat
The first line contains two integers (n) and (m) (where (1 \leq n \leq 10^5) and (1 \leq m \leq n)). The second line contains (n) integers (A_1, A_2, \dots, A_n), where (A_i) represents the aesthetic value of the i-th position.
outputFormat
Output a single line containing the maximum total aesthetic value achievable if it is possible to plant all (m) trees. Otherwise, output the string impossible
(all lowercase).
sample
5 2
1 2 3 4 5
9
</p>