You have been invited to a TV game show where you will play against another contestant to win free guitars. At the start of the game, there are n guitar cases arranged in a circle, each of which contains a single guitar. You make the first move by choosing one guitar and removing it from its case. The other player then chooses a guitar and removes it from its case. At this point, there might be one or two groups, where a group is defined as a maximal contiguous set of non-empty cases. You continue to take turns choosing guitars, and on each turn, the current player chooses exactly one guitar from each group. The game ends when all the guitars have been chosen.
Each player gets to keep all the guitars that he chooses during the game. Your goal is to maximize the total value of the guitars you choose. The guitars in the circle are numbered 0 to n-1 in clockwise order (guitar 0 is next to guitar n-1). You are given a int[] guitarValues, the i-th element of which is the value of guitar i. Return the maximum possible total value you can get, assuming your opponent plays a perfect strategy.
|