Multi-judge Solving
Contest: Educational Codeforces Round 25
Difficulty rating: 1600
Tags: greedy, implementation

Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Decoforces is as hard as the problem with difficulty d on any other judge).

Makes has chosen n problems to solve on Decoforces with difficulties a1, a2, ..., an. He can solve these problems in arbitrary order. Though he can solve problem i with difficulty ai only if he had already solved some problem with difficulty $$d \geq \frac{a_i}{2}$$ (no matter on what online judge was it).

Before starting this chosen list of problems, Makes has already solved problems with maximum difficulty k.

With given conditions it's easy to see that Makes sometimes can't solve all the chosen problems, no matter what order he chooses. So he wants to solve some problems on other judges to finish solving problems from his list.

For every positive integer y there exist some problem with difficulty y on at least one judge besides Decoforces.

Makes can solve problems on any judge at any time, it isn't necessary to do problems from the chosen list one right after another.

Makes doesn't have too much free time, so he asked you to calculate the minimum number of problems he should solve on other judges in order to solve all the chosen problems from Decoforces.

Input format:
The first line contains two integer numbers n, k (1 ≤ n ≤ 103, 1 ≤ k ≤ 109).

The second line contains n space-separated integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109).

Output format:
Print minimum number of problems Makes should solve on other judges in order to solve all chosen problems on Decoforces.

Constraints:
Time limit: 1.0 s
Memory limit: 256.0 MB

Note:
In the first example Makes at first solves problems 1 and 2. Then in order to solve the problem with difficulty 9, he should solve problem with difficulty no less than 5. The only available are difficulties 5 and 6 on some other judge. Solving any of these will give Makes opportunity to solve problem 3.

In the second example he can solve every problem right from the start.

Example input:
3 3
2 1 9

Example output:
1

Example input:
4 20
10 3 6 3

Example output:
0

Editorial:
Obviously sorting the tasks by difficulty will always produce the most optimal order of solving. In that case ability to solve some task i will mean ability to solve any task from 1 to i - 1.
Now let's maintain the upper limit of difficulty of problem Makes is able to solve. Right after solving some problem i it will be 2·max(k, ai). Initially it's just 2·k.
Transition from i to i + 1 will then look like this. If the upper limit it greater or equal to ai + 1 then we solve this problem and update the upper limit. Otherwise we will need some problems from other judges. As our goal is to maximize the upper limit, the most optimal task to solve is the hardest possible. So you should solve task with the difficulty of upper limit and update the limit itself. Keep doing it until upper limit becomes grater or equal to ai + 1.
You will require no more then $$\left\lceil \log a_{n} \right\rceil$$ tasks from the other judges. By algorithm it's easy to see that by solving task with difficulty d we update upper limit with the value 2·d. This function produces such a estimate.
Overall complexity: $${\mathcal {O}}(n\cdot \log n+\log \max a_{i})$$.