#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 nn small vegetable plots in order, numbered from 11 to nn. Plot ii and plot i+1i+1 are adjacent. Since the garden is circular, plot 11 and plot nn are also adjacent.

Now, plot ii has rir_i rabbits. JYY's rifle has kk 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 ii, then the rabbits on plot i+1i+1 will run to plot i+2i+2. Similarly, the rabbits on plot i1i-1 will run to plot i2i-2. JYY wants to know how to use these kk bullets to eliminate as many rabbits as possible.

Input Format

The first line contains two integers nn and kk.

The second line contains nn integers, where the ii-th integer is rir_i.

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 11, which becomes 0 0 6 7 00\ 0\ 6\ 7\ 0. Then fire at plot 44. It can be proven that there is no answer greater than 1313.

Constraints

For 100%100\% of the testdata, 3n40003\leq n\leq 4000, 0k40000\leq k\leq 4000, ri105r_i\leq 10^5.

Translated by ChatGPT 5