Company: Agoda_16nov
Difficulty: medium
Wallet Denominations A wallet holds n banknotes. The value of the i -th note is money[i] . You may repeatedly apply the following operation. Pick one note whose current value is x and pay $1 to replace that value by any other integer y in the range floor(x / 2) <= y <= 2 * x (y >= 1, y != x) In words: a single dollar either raises a note to at most double its value, or lowers it to at least half its value (halving rounds down , so a note worth 3 can be turned into 1 for one dollar). A note is never allowed to drop below 1 , and an operation must change the value — paying to keep the same value is not a thing. The same note may be operated on as many times as you like, each time for a further $1. Find the minimum number of dollars needed to make all n notes equal. Input Format The first line contains a single integer n , the number of notes. The second line contains n space-separated integers money[0] … money[n-1] . Output Format Print a single integer — the minimum total cost