#P13552. 鱼类考古学

    ID: 11599 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>贪心洛谷原创O2优化位运算洛谷月赛

鱼类考古学

Description

You accidentally obtained nn non-negative integers, where the ii-th number is aia_i.

Since there are too many numbers to store at home, you decide to merge them into a single number.

You can perform two types of operations:

  1. Choose two numbers xx and yy, then merge them into a new number xyx \otimes y.
  2. Choose two numbers xx and yy, then merge them into a new number x+yx + y.

Here, \otimes denotes the bitwise AND operation. The two numbers chosen do not need to be adjacent.

Due to certain constraints, you must use Operation 1 exactly nkn-k times in the n1n-1 steps of merging. Your task is to maximize the final remaining number.

To help you understand the problem, here’s an example for n=3n=3, k=2k=2, and a=[1,2,3]a=[1, 2, 3]:

  1. Use Operation 2 to merge 11 and 22 into 33. Now aa becomes [3,3][3, 3].
  2. Use Operation 1 to merge 33 and 33 into 33. Now aa becomes [3][3].

Input Format

Each test case contains TT sets of inputs.

For each test case:

  • The first line contains two integers, nn and kk.
  • The second line contains nn integers, where the ii-th integer is aia_i.

Output Format

Output a single integer representing the answer.

3
3 2
1 2 3
4 3
2 5 6 4
5 1
1 3 7 9 11
3
12
1

Hint

  • For Sample 1, the explanation is provided in the problem description.
  • For Sample 2, merge 55 and 44 using Operation 1, then use Operation 2 for the remaining merges. It can be proven that no solution yields a result greater than 1212.
  • For Sample 3, the only possible answer is merging all numbers using Operation 1.

Data Range

Sub Points nn \le kk \le Special Constraints
11 1111 55 popc(ai)3\operatorname{popc}(a_i) \le 3
22 1515 5050 1010 popc(ai)1\operatorname{popc}(a_i) \le 1
33 2121 10510^5 22 None
44 2626 10510^5 popc(ai)3\operatorname{popc}(a_i) \le 3
55 2727 10610^6 None

Here, popc(x)\operatorname{popc}(x) denotes the number of 11s in the binary representation of xx.

For all test cases:

  • 1T1051 \le T \le 10^5,
  • 1kn1061 \le k \le n \le 10^6,
  • 0ai<2300 \le a_i < 2^{30},
  • The sum of nn across all test cases does not exceed 2×1062 \times 10^6.

Special Note: For Subtask 1, T5T \le 5.

Generated by Deepseek V3.