Jonathan Sumabat 3

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

Jonathan Sumabat is entering a badminton tournament. This tournament is a single bracket where each other player is matched against the player before them. The winner of each of these matches moves on to the next round. Each of the winners are matched against each other again in the same way and this is repeated until only one player remains. Jonathan Sumabat has done extensive research on all his opponents and has assigned a "power level" for each of them, representing their skill. A person with a certain skill level is guaranteed to defeat any player with a lower skill level and in turn will lose to any player of higher skill level. Jonathan Sumabat also knows his own skill level. Using the skill levels, determine how far Jonathan Sumabat will make it into the tournament.

Input Specification

The first line is n (2 \le n \le 2^{19}) representing the number of players in the tournament. This number is always a perfect power of 2.
The next n lines is n_i (1 \le n_i \le 10^6) representing the power level of player i in the tournament. Jonathan Sumabat is always the first player. No two players will have the same power level.

Output Specification

Output a single integer representing the round at which Jonathan Sumabat will lose. For example if he loses his first game, output 1. If he wins the entire tournament output the total number of rounds in the tournament plus 1.

Sample Input

8
70
50
67
55
99
90
66
23

Sample Output

3

Explanation for Sample

Jonathan Sumabat has a power level of 70 and is matched against a player with power level of 50. He will defeat this player then play someone of power level 67, who has defeated the person with power level 55. He will defeat the person of power level 67 then lose to the player with power level 99 on round 3.


Comments

There are no comments at the moment.