#P7240. [JSOI2014] 打兔子
[JSOI2014] 打兔子
Description
Hardworking JYY planted a lot of carrots in his garden. But this morning, JYY found that a large group of rabbits from the Kingdom of JSOI had occupied his entire garden. The rabbits ate all the carrots—how will JYY survive the winter? Unable to tolerate it anymore, JYY decided to take out his powerful hunting rifle to eliminate these rabbits.
JYY's garden is a circular ring formed by connecting small vegetable plots in order, numbered from to . Plot and plot are adjacent. Since the garden is circular, plot and plot are also adjacent.
Now, plot has rabbits. JYY's rifle has bullets. Each time, JYY can choose one plot and fire one shot, and all rabbits on that plot will be eliminated. However, because the rifle is too powerful, it will scare the rabbits on adjacent plots. So, if JYY fires at plot , then the rabbits on plot will run to plot . Similarly, the rabbits on plot will run to plot . JYY wants to know how to use these bullets to eliminate as many rabbits as possible.
Input Format
The first line contains two integers and .
The second line contains integers, where the -th integer is .
Output Format
Output one integer in one line, representing the maximum number of rabbits JYY can eliminate.
5 2
6 1 5 3 4
13
Hint
Sample Explanation
First, fire at plot , which becomes . Then fire at plot . It can be proven that there is no answer greater than .
Constraints
For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号