#P6064. [USACO05JAN] Naptime G
[USACO05JAN] Naptime G
Problem Description
Bessie is a very sleep-deprived cow. Her day is evenly divided into time segments (), and she wants to sleep for of them (). Each segment has a utility value (), 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 and time , then she will gain the utility value of time .
Input Format
The first line contains two integers .
The next lines each contain one integer, representing the utility value of the -th time segment.
Output Format
Output the maximum total utility.
5 3
2
0
3
1
4
6
Hint
Fall asleep starting from the -th time segment, and wake up at the end of the -st time segment.
Translated by ChatGPT 5