Avito Code Challenge 2018
D
Bookshelves
Codeforces
1900
原题
← CE →
翻译中…

Mr Keks is a typical white-collar in Byteland.

翻译中…

He has a bookshelf in his office with some books on it, each book has an integer positive price.

翻译中…

Mr Keks defines the value of a shelf as the sum of books prices on it.

翻译中…

Miraculously, Mr Keks was promoted and now he is moving into a new office.

翻译中…

He learned that in the new office he will have not a single bookshelf, but exactly $k$ bookshelves. He decided that the beauty of the $k$ shelves is the bitwise AND of the values of all the shelves.

翻译中…

He also decided that he won't spend time on reordering the books, so he will place several first books on the first shelf, several next books on the next shelf and so on. Of course, he will place at least one book on each shelf. This way he will put all his books on $k$ shelves in such a way that the beauty of the shelves is as large as possible. Compute this maximum possible beauty.

翻译中…

Input

翻译中…

The first line contains two integers $n$ and $k$ ($1 \leq k \leq n \leq 50$) — the number of books and the number of shelves in the new office.

翻译中…

The second line contains $n$ integers $a_1, a_2, \ldots a_n$, ($0 \lt a_i \lt 2^{50}$) — the prices of the books in the order they stand on the old shelf.

翻译中…

Output

翻译中…

Print the maximum possible beauty of $k$ shelves in the new office.

翻译中…

Note

翻译中…

In the first example you can split the books as follows:

翻译中…

$$(9 + 14 + 28 + 1 + 7) \& (13 + 15) \& (29 + 2) \& (31) = 24.$$

翻译中…

In the second example you can split the books as follows:

翻译中…

$$(3 + 14 + 15 + 92) \& (65) \& (35 + 89) = 64.$$

翻译中…

样例

Input #1
10 4
9 14 28 1 7 13 15 29 2 31
Output #1
24
InputCopy OutputCopy
Input #2
7 3
3 14 15 92 65 35 89
Output #2
64
InputCopy OutputCopy
题目信息
题号
981D
时间限制
1 s
内存限制
256 MB
标签
位运算
动态规划
贪心

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。