#P8641. [蓝桥杯 2016 国 C] 赢球票
[蓝桥杯 2016 国 C] 赢球票
Problem Description
An organization is holding a ticket grand prize game. Winning contestants have a chance to win several tickets.
The host takes out cards (labeled with the numbers ), shuffles them, and arranges them in a circle.
You may start from any card and count clockwise: .
If the number you count is exactly the same as the number on the current card, you take that card. Then restart counting from the next card.
The game ends when you can no longer take any card. The sum of the numbers on the cards you have taken is the number of tickets you win.
For example:
The card order is: .
If we start counting from card , we take card . Then we start from card , but the counted numbers can no longer match the card numbers.
Soon the counted numbers become larger and larger, and it is impossible to take any more cards. So this time we win only ticket.
That is not too bad. If we foolishly start counting from card or , we cannot get any card at all.
If we are lucky and the card order is .
Then we can successfully take all the cards.
The goal of this problem is: given the clockwise card sequence, you may start counting from anywhere. Find the maximum number of tickets you can win (i.e., the sum of the numbers on the cards you take).
Input Format
The first line contains an integer , the number of cards.
The second line contains integers, the cards in clockwise order.
Output Format
One line with one integer, the maximum number of tickets you can win in the best case.
3
1 2 3
1
3
2 1 3
6
Hint
Time limit: 1 s, 256 MB. Lanqiao Cup 2016, the 7th National Final.
Translated by ChatGPT 5