P10512 Sequence Merging

Description

Given a non-negative integer sequence $\{a_n\}$ of length $n$, you can perform $k$ operations. In each operation, you choose two adjacent numbers and merge them into their bitwise OR. Formally, in one operation, you choose an index $i$ ($1 \le i < n$), and then the original sequence becomes $\{a_1,a_2,\cdots,a_i \operatorname{or} a_{i+1},a_{i+2},\cdots,a_n\}$. Find the maximum possible value of the bitwise AND of all numbers after $k$ operations.

Input Format

The first line contains two positive integers $n, k$. The second line contains $n$ non-negative integers, where the $i$-th non-negative integer is $a_i$.

Output Format

Output one line containing one positive integer, which is the answer.

Explanation/Hint

**[Sample Explanation]** One valid plan: - In the first operation, merge the first and second numbers, and the sequence becomes $\{3,2,3,1\}$. - In the second operation, merge the third and fourth numbers, and the sequence becomes $\{3,2,3\}$. The final bitwise AND of all numbers is $2$. It can be proven that there is no better plan. **[Constraints]** - For $25\%$ of the testdata, $n \le 20$. - For another $25\%$ of the testdata, $k = n - 2$. For all testdata, it is guaranteed that $1 \le k < n \le 2 \times 10^5$, $0 \le a_i < 2^{30}$. Translated by ChatGPT 5