CF1609A.Divide and Multiply

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

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=aj⋅2a_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.

威廉有一个包含 nn 个数的数组 a1,a2,…,ana_1, a_2, \dots, a_n。他可以任意多次执行以下操作序列:

  1. 从数组中任选两个元素 aia_i 和 aja_j,其中 aia_i 必须是 22 的倍数;
  2. 将 aia_i 替换为 ai2\frac{a_i}{2};
  3. 将 aja_j 替换为 aj⋅2a_j \cdot 2。

请帮助威廉求出通过执行上述操作所能得到的数组元素之和的最大值。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). Description of the test cases follows.

The first line of each test case contains an integer nn (1≤n≤15)(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 (1≤ai<16)(1 \le a_i \lt 16), the contents of William's array.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤151 \le n \le 15),表示 William 数组中的元素个数。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai<161 \le a_i \lt 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:

  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=6⋅2=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=12⋅2=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=24⋅2=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.

在第一个样例测试用例中,最优操作序列为:

  1. 选择 i=2i = 2 和 j=1j = 1。执行一系列操作后,a2=42=2a_2 = \frac{4}{2} = 2,a1=6⋅2=12a_1 = 6 \cdot 2 = 12,数组变为:[12, 2, 2]。
  2. 选择 i=2i = 2 和 j=1j = 1。执行一系列操作后,a2=22=1a_2 = \frac{2}{2} = 1,a1=12⋅2=24a_1 = 12 \cdot 2 = 24,数组变为:[24, 1, 2]。
  3. 选择 i=3i = 3 和 j=1j = 1。执行一系列操作后,a3=22=1a_3 = \frac{2}{2} = 1,a1=24⋅2=48a_1 = 24 \cdot 2 = 48,数组变为:[48, 1, 1]。

最终答案为 48+1+1=5048 + 1 + 1 = 50。

在第三个样例测试用例中,无法改变元素之和,因此答案为 1010。

输入解题思路,AI测评打分。不知道怎么写?

首页