Best Solution Unknown
Time limit3sMemory limit512 MB
Each match removes one of two adjacent players, and the stronger one wins and gains 1 strength. List every index that can end as the sole winner.
- Level
Hard8 of 10
- Topics
- Stack, Greedy, Binary search
- Solved
- No attempts yet
Statement
You are the responsible holder of a competition called Best Solution Unknown (BSU). The rules of this competition are simple but rather quirky.
First, all the participants stand in a row. Then, matches are held. In each match, the jury chooses two adjacent players. The chosen players are given an NP-hard problem, and they try their best to come up with a good solution. The one who provides a better solution wins a round, and the other one leaves the competition. After that, the players shift to form a valid row again, so the player adjacent to the player who left becomes adjacent to the winner. After all matches, only one player remains, and this player is declared the winner of the competition.
The strength of the -th player, counting from the left, is . You know the strength of each player before the competition. A player with greater strength wins the match. If the strengths are equal, either player may win. The strength of the winner of a match increases by one.
You do not know who plays in each match, or who wins a match when the strengths are equal. Find every participant who can become the winner of the competition.
Input
The first line contains (), the number of participants. The second line contains integers (), the initial strength of the -th participant.
Output
The first line should contain (), the number of participants that can possibly win. The second line should contain integers in strictly increasing order, the indices of these participants ().