P13552 魚類による考古学

Background

[魚類による考古学](https://music.163.com/song?id=1493975799&uct2=U2FsdGVkX18z3QdJXIcIlC4TpfGnVAHDxBxQd8lpYlI=)。 > 生まれていいかって訊いた / 君はいいよって言った > > 君が僕を選ぶとき / 僕が君を選んだの

Description

You accidentally obtained $n$ non-negative integers, where the $i$-th number is $a_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 $x$ and $y$, then merge them into a new number $x \otimes y$. 2. Choose two numbers $x$ and $y$, then merge them into a new number $x + 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 $n-k$ times** in the $n-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=3$, $k=2$, and $a=[1, 2, 3]$: 1. Use **Operation 2** to merge $1$ and $2$ into $3$. Now $a$ becomes $[3, 3]$. 2. Use **Operation 1** to merge $3$ and $3$ into $3$. Now $a$ becomes $[3]$.

Input Format

Each test case contains $T$ sets of inputs. For each test case: - The first line contains two integers, $n$ and $k$. - The second line contains $n$ integers, where the $i$-th integer is $a_i$.

Output Format

Output a single integer representing the answer.

Explanation/Hint

- For Sample 1, the explanation is provided in the problem description. - For Sample 2, merge $5$ and $4$ using **Operation 1**, then use **Operation 2** for the remaining merges. It can be proven that no solution yields a result greater than $12$. - For Sample 3, the only possible answer is merging all numbers using **Operation 1**. ### Data Range | Sub | Points | $n \le$ | $k \le$ | Special Constraints | | :--: | :--: | :--: | :--: | :--: | | $1$ | $11$ | $5$ | $5$ | $\operatorname{popc}(a_i) \le 3$ | | $2$ | $15$ | $50$ | $10$ | $\operatorname{popc}(a_i) \le 1$ | | $3$ | $21$ | $10^5$ | $2$ | None | | $4$ | $26$ | $10^5$ | $10^5$ | $\operatorname{popc}(a_i) \le 3$ | | $5$ | $27$ | $10^6$ | $10^6$ | None | Here, $\operatorname{popc}(x)$ denotes the number of $1$s in the binary representation of $x$. For all test cases: - $1 \le T \le 10^5$, - $1 \le k \le n \le 10^6$, - $0 \le a_i < 2^{30}$, - The sum of $n$ across all test cases does not exceed $2 \times 10^6$. **Special Note:** For Subtask 1, $T \le 5$. Generated by Deepseek V3.