Codeforces Round 1116 (Div. 2)
F
How Long Until Nothing Remains?
Codeforces
未评级
原题
← E→

How Long Until Nothing Remains?AI (CI翻译)

Before her final sortie, Chtholly asks Willem three questions.

The first is this: if the end is inevitable, how long will it take until nothing remains?

Willem cannot answer her directly. Instead, he writes down $n$ positive integers $a_1,a_2,\ldots,a_n$.

Each operation takes one second. In one operation, Willem does the following:

  • Choose an index $p$ ($1\le p\le n$);
  • Then, replace $a_p$ with $\left\lfloor\dfrac{a_p}{2}\right\rfloor$, and for every $i\ne p$, replace $a_i$ by $\left\lceil\dfrac{a_i}{2}\right\rceil$. All replacements are performed simultaneously.

Find the minimum number of seconds needed to make all $n$ integers equal to $0$.

Input

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

The first line of each test case contains one integer $n$ ($1\le n\le2\cdot10^5$) — the number of integers.

The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ($1\le a_i\le10^9$) — the initial integers.

It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot10^5$.

Output

For each test case, output a single integer — the minimum number of seconds needed to make all integers equal to $0$.

Note

In the first test case, the only integer changes as $3\to1\to0$, so the answer is $2$.

In the second test case, an integer equal to $1$ becomes $0$ only when its index is chosen. Thus, at least $3$ seconds are necessary, and choosing every index once is sufficient.

In the third test case, an optimal sequence is:

  1. Choose $p=1$: $[1,2,4]\to[0,1,2]$;
  2. Choose $p=2$: $[0,1,2]\to[0,0,1]$;
  3. Choose $p=3$: $[0,0,1]\to[0,0,0]$.

In the fourth test case, an optimal sequence is $[5,2]\to[2,1]\to[1,0]\to[0,0]$, where the chosen indices are $1$, $2$, and $1$.

{"titleZh":"还要多久才会什么都不剩?","bodyZh":"## 题目描述\n\n在她最后一次出击前,Chtholly 向 Willem 提出了三个问题。\n\n第一个问题是:既然终焉不可避免,那么要过多久才会什么都不剩?\n\nWillem 无法直接回答她。于是,他写下了 $n$ 个正整数 $a_1,a_2,\\ldots,a_n$。\n\n每次操作耗时一秒。在一次操作中,Willem 进行如下操作:\n\n- 选择一个下标 $p$($1\\le p\\le n$);\n- 将 $a_p$ 替换为 $\\left\\lfloor\\dfrac{a_p}{2}\\right\\rfloor$,并将对于每个 $i\\ne p$ 的 $a_i$ 替换为 $\\left\\lceil\\dfrac{a_i}{2}\\right\\rceil$。所有替换同时进行。\n\n求使全部 $n$ 个整数都变为 $0$ 所需的最少秒数。\n\n## 输入格式\n\n每个测试包含多个测试用例。第一行包含测试用例数量 $t$($1 \\le t \\le 10^4$)。接下来是各测试用例的描述。\n\n每个测试用例的第一行包含一个整数 $n$($1\\le n\\le2\\cdot10^5$)——整数的数量。\n\n每个测试用例的第二行包含 $n$ 个整数 $a_1,a_2,\\ldots,a_n$($1\le a_i\\le10^9$)——初始的整数。\n\n保证所有测试用例中 $n$ 的总和不超过 $2\\cdot10^5$。\n\n## 输出格式\n\n对于每个测试用例,输出一个整数——使全部整数都变为 $0$ 所需的最少秒数。\n\n## 说明\n\n在第一个测试用例中,唯一的整数按 $3\\to1\\to0$ 变化,因此答案为 $2$。\n\n在第二个测试用例中,等于 $1$ 的整数只有在其下标被选中时才会变为 $0。因此,至少需要 $3$ 秒,而将每个下标都选择一次即可满足要求。\n\n在第三个测试用例中,一种最优操作序列为:\n\n1. 选择 $p=1$:$[1,2,4]\to[0,1,2]$;\n2. 选择 $p=2$:$[0,1,2]\to[0,0,1]$;\n3. 选择 $p=3$:$[0,0,1]\to[0,0,0]$。\n\n在第四个测试用例中,一种最优操作序列为 $[5,2]\to[2,1]\to[1,0]\to[0,0]$,其中选择的下标依次为 $1$、$2$、$1$。"}AI (CI翻译)

样例

Input #1
5
1
3
3
1 1 1
3
1 2 4
2
5 2
6
1 2 3 4 5 6
Output #1
2
3
3
3
6
InputCopy OutputCopy
题目信息
题号
2256F
时间限制
2 s
内存限制
256 MB

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。