CF1609A.Divide and Multiply
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述

William has array of n numbers a1,a2,…,an. He can perform the following sequence of operations any number of times:
- Pick any two items from array ai and aj, where ai must be a multiple of 2
- ai=2ai
- aj=aj⋅2
Help William find the maximal sum of array elements, which he can get by performing the sequence of operations described above.

威廉有一个包含 n 个数的数组 a1,a2,…,an。他可以任意多次执行以下操作序列:
- 从数组中任选两个元素 ai 和 aj,其中 ai 必须是 2 的倍数;
- 将 ai 替换为 2ai;
- 将 aj 替换为 aj⋅2。
请帮助威廉求出通过执行上述操作所能得到的数组元素之和的最大值。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). Description of the test cases follows.
The first line of each test case contains an integer n (1≤n≤15), the number of elements in William's array.
The second line contains n integers a1,a2,…,an (1≤ai<16), the contents of William's array.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤15),表示 William 数组中的元素个数。
第二行包含 n 个整数 a1,a2,…,an(1≤ai<16),即 William 数组的内容。
输出格式
For each test case output the maximal sum of array elements after performing an optimal sequence of operations.
对于每个测试用例,输出执行最优操作序列后数组元素的最大和。
输入输出样例
输入#1
5 3 6 4 2 5 1 2 3 4 5 1 10 3 2 3 4 15 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8
输出#1
50 46 10 26 35184372088846
说明/提示
In the first example test case the optimal sequence would be:
- Pick i=2 and j=1. After performing a sequence of operations a2=24=2 and a1=6⋅2=12, making the array look as: [12, 2, 2].
- Pick i=2 and j=1. After performing a sequence of operations a2=22=1 and a1=12⋅2=24, making the array look as: [24, 1, 2].
- Pick i=3 and j=1. After performing a sequence of operations a3=22=1 and a1=24⋅2=48, making the array look as: [48, 1, 1].
The final answer 48+1+1=50.
In the third example test case there is no way to change the sum of elements, so the answer is 10.
在第一个样例测试用例中,最优操作序列为:
- 选择 i=2 和 j=1。执行一系列操作后,a2=24=2,a1=6⋅2=12,数组变为:[12, 2, 2]。
- 选择 i=2 和 j=1。执行一系列操作后,a2=22=1,a1=12⋅2=24,数组变为:[24, 1, 2]。
- 选择 i=3 和 j=1。执行一系列操作后,a3=22=1,a1=24⋅2=48,数组变为:[48, 1, 1]。
最终答案为 48+1+1=50。
在第三个样例测试用例中,无法改变元素之和,因此答案为 10。
输入解题思路,AI测评打分。不知道怎么写?