CF1609A.Divide and Multiply

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

William has array of nn numbers a1,a2,,ana_1, a_2, \dots, a_n . He can perform the following sequence of operations any number of times:

  1. Pick any two items from array aia_i and aja_j , where aia_i must be a multiple of 22
  2. ai=ai2a_i = \frac{a_i}{2}
  3. aj=aj2a_j = a_j \cdot 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 tt ( 1t1041 \le t \le 10^4 ). Description of the test cases follows.

The first line of each test case contains an integer nn (1n15)(1 \le n \le 15) , the number of elements in William's array.

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ai<16)(1 \le a_i < 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:

  1. Pick i=2i = 2 and j=1j = 1 . After performing a sequence of operations a2=42=2a_2 = \frac{4}{2} = 2 and a1=62=12a_1 = 6 \cdot 2 = 12 , making the array look as: [12, 2, 2].
  2. Pick i=2i = 2 and j=1j = 1 . After performing a sequence of operations a2=22=1a_2 = \frac{2}{2} = 1 and a1=122=24a_1 = 12 \cdot 2 = 24 , making the array look as: [24, 1, 2].
  3. Pick i=3i = 3 and j=1j = 1 . After performing a sequence of operations a3=22=1a_3 = \frac{2}{2} = 1 and a1=242=48a_1 = 24 \cdot 2 = 48 , making the array look as: [48, 1, 1].

The final answer 48+1+1=5048 + 1 + 1 = 50 .

In the third example test case there is no way to change the sum of elements, so the answer is 1010 .

首页