F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Multiply 2 Divide 2

Time Limit: 15000/7500 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 177    Accepted Submission(s): 63


Problem Description
$\textbf{Note:There is no dependency between this problem and problem Hack of Multiply 2 Divide 2.}$

Frank_DD has a sequence $a$ of length $n$.

For each operation, he selects a number $a_i(1 \le i \le n)$ and changes it to $a_i\cdot 2$ or $\lfloor \frac{a_i}{2} \rfloor$.

Frank_DD wants to know the minimum number of operations to change the sequence $a$ to a non-descending sequence.
 

Input
The first line of the input contains one integer $T$ $($$1\leq T\leq 5$ $)$ --- the number of test cases. Then $T$ test cases follow.

In each test case:

The first line contains a single integer $n(1 \leq n \leq 10^5)$ --- the length of sequence $a$.

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ $(1 \leq a_i \leq 10^5)$ --- the sequence $a$.
 

Output
For each test case, print a single integer in a single line --- the minimum number of operations to change the sequence $a$ to a non-descending sequence.
 

Sample Input
2 7 6 3 3 4 10 8 2 10 9 9 4 7 3 10 10 8 4 3
 

Sample Output
4 11
 

Hint

In the first test case, we can use at least 4 operations to change the sequence $a$ to a non-descending sequence:

$a_1=\lfloor \frac{a_1}{2} \rfloor$

$a_5=\lfloor \frac{a_5}{2} \rfloor$

$a_7=a_7 \cdot 2$

$a_7=a_7 \cdot 2$
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-21 10:36:20, Gzip enabled