CF1609A.Divide and Multiply
普及/提高-
通过率:0%
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.
输入格式
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.
输出格式
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 .