A9883 | Amr and Chemistry
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment.
Amr has $n$ different types of chemicals. Each chemical $i$ has an initial volume of $a_{i}$ liters. For this experiment, Amr has to mix all the chemicals together, but all the chemicals volumes must be equal first. So his task is to make all the chemicals volumes equal.
To do this, Amr can do two different kind of operations.
- Choose some chemical $i$ and double its current volume so the new volume will be $2a_{i}$
- Choose some chemical $i$ and divide its volume by two (integer division) so the new volume will be 
Suppose that each chemical is contained in a vessel of infinite volume. Now Amr wonders what is the minimum number of operations required to make all the chemicals volumes equal?
Amr has $n$ different types of chemicals. Each chemical $i$ has an initial volume of $a_{i}$ liters. For this experiment, Amr has to mix all the chemicals together, but all the chemicals volumes must be equal first. So his task is to make all the chemicals volumes equal.
To do this, Amr can do two different kind of operations.
- Choose some chemical $i$ and double its current volume so the new volume will be $2a_{i}$
- Choose some chemical $i$ and divide its volume by two (integer division) so the new volume will be 
Suppose that each chemical is contained in a vessel of infinite volume. Now Amr wonders what is the minimum number of operations required to make all the chemicals volumes equal?
输入格式
The first line contains one number $n$ ( $1<=n<=10^{5}$ ), the number of chemicals.
The second line contains $n$ space separated integers $a_{i}$ ( $1<=a_{i}<=10^{5}$ ), representing the initial volume of the $i$ -th chemical in liters.
The second line contains $n$ space separated integers $a_{i}$ ( $1<=a_{i}<=10^{5}$ ), representing the initial volume of the $i$ -th chemical in liters.
输出格式
Output one integer the minimum number of operations required to make all the chemicals volumes equal.
输入输出样例
输入 #1
3 4 8 2
输出 #1
2
输入 #2
3 3 5 6
输出 #2
5
In the first sample test, the optimal solution is to divide the second chemical volume by two, and multiply the third chemical volume by two to make all the volumes equal $4$ .
In the second sample test, the optimal solution is to divide the first chemical volume by two, and divide the second and the third chemical volumes by two twice to make all the volumes equal $1$ .
In the second sample test, the optimal solution is to divide the first chemical volume by two, and divide the second and the third chemical volumes by two twice to make all the volumes equal $1$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted