The Shell Game
Time limit1sMemory limit256 MB
Buy interval parity hints to fix every ball position while minimizing the worst-case total price.
- Level
Medium6 of 10
- Topics
- Minimum spanning tree, Graph
- Solved
- No attempts yet
Problem
Bitocy makes a living running a shell game at the fair. On a table stand cups in a row, numbered to , and a rubber ball is hidden under some of them. A customer who names exactly the cups that hide a ball wins a large teddy bear.
Bitocy sells hints. For coins he tells you whether the number of balls hidden under cups through is even or odd.
Bajtazar came to the fair with Bajtyna and wants to win the bear for her. He will not guess while he is unsure, so he keeps buying hints until the answers he has bought fix the position of every ball.
He knows the price of every hint and wants the worst case. Find the smallest such that some strategy of asking questions locates all the balls for at most coins, whatever Bitocy answers.
Input
The first line contains the number of cups ().
The next lines give the hint prices. Line of those contains integers, and the -th of them is the price of the question about cups through (, ).
Output
Print one integer, the largest amount that locating all the balls costs under the optimal strategy.