Windblume Festival
Time limit3sMemory limit1024 MB
Players in a circle repeatedly remove a neighbor and subtract its value from the player before it, and the task is to find the maximum value the last player can hold.
- Level
Medium6 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
The Windblume Festival in Mondstadt is coming! People are preparing windblumes for Barbatos and for those they love and adore. The Windblume Festival is also an opportunity to improve the relationships people have.
Source: Genshin Impact Official. During the festival, a famous game is played every year, invented by Jean, the Acting Grand Master of the Knights of Favonius. In the game, players numbered from to stand in a circle, each holding an integer. Each turn, one player is removed. The game ends when only one player is left. For each turn, let be the number of players remaining and be the integer player holds. Two adjacent players, and , are selected, and player is removed from the game. Player 's integer then changes from to . Player in this turn becomes player in the next turn for all , though the integer they hold does not change. Jean wants to know the maximum possible integer held by the last remaining player by selecting the players in each round optimally.
Input
There are multiple test cases. The first line of the input contains one integer , the number of test cases. For each test case: The first line contains one integer (), the initial number of players. The next line contains integers (), where is the integer held by player at the beginning. It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output one line containing one integer, the maximum possible integer.
Hint
For the first sample test case, follow the strategy shown below, where the underlined integers are the integers held by the players selected in each turn. (select ) (select ) (select ) .