#P6064. [USACO05JAN] Naptime G

[USACO05JAN] Naptime G

Problem Description

Bessie is a very sleep-deprived cow. Her day is evenly divided into NN time segments (3N38303 \leq N \leq 3830), and she wants to sleep for BB of them (2B<N2 \leq B \lt N). Each segment has a utility value UiU_i (0Ui2×1050 \leq U_i \leq 2 \times 10^5), which only counts when she is sleeping.

With the help of an alarm clock, Bessie can choose to fall asleep at any time. Of course, she can only fall asleep and wake up at the boundaries between segments.

Bessie wants to maximize the total utility gained during sleep. Unfortunately, the first segment of each sleep period is the “falling asleep” segment and does not contribute any utility.

The time segments form a cycle (days repeat). If Bessie sleeps across time NN and time 11, then she will gain the utility value of time 11.

Input Format

The first line contains two integers N,BN, B.

The next NN lines each contain one integer, representing the utility value of the ii-th time segment.

Output Format

Output the maximum total utility.

5 3
2
0
3
1
4
6

Hint

Fall asleep starting from the 44-th time segment, and wake up at the end of the 11-st time segment.

Translated by ChatGPT 5