atcoder#ARC138C. [ARC138C] Rotate and Play Game
[ARC138C] Rotate and Play Game
Score : points
Problem Statement
There are cards, indexed to . Card has an integer written on it. Here, is even.
Snuke and Mr. Min will play a game. The game consists of turns, alternately taken by the two players, with Snuke going first. In each turn, the player does the following operation.
- In Snuke's turn: He takes any card of his choice that is not taken by anyone yet.
- In Mr. Min's turn: He takes the card with the minimum index that is not taken by anyone yet.
Snuke's score will be the sum of the integers written on the cards taken by Snuke. Snuke plays optimally to maximize the score.
Incidentally, being a big fan of Snuke, you are planning to do something nasty to maximize the score. Specifically, before the start of the game, you will do the following action once.
- Choose an integer () and cyclically shift the integers written on the cards by to the left: the cards will have written on them.
Find the value that you should choose to maximize the score, and the resulting score when choosing that .
Constraints
- is even.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer in the following format:
Here, is the integer you choose (), and is the score when choosing that . If there are multiple values of that maximize , printing any of them will be accepted.
4
3 4 1 2
1 7
If you choose , the cards will have written on them. Then, the game will go as follows.
- Snuke takes Card .
- Mr. Min takes Card .
- Snuke takes Card .
- Mr. Min takes Card .
In this case, Snuke's score is .
In this input, will also be accepted.
2
1 1
0 1
10
716893678 779607519 555600775 393111963 950925400 636571379 912411962 44228139 15366410 2063694
7 3996409938