P26426 [AtCoder] Sum AND Subarrays
普及+
题目描述

Problem Description

One day, Niwango, a Dwango employee, found an integer sequence of length $ N $: $(a_1,\ ...,\ a_N)$. Niwango is interested in the properties of this sequence.

The beauty of a non-empty contiguous subsequence $a_l,\ ...,\ a_r$ $(1\ \leq\ l\ \leq\ r\ \leq\ N)$ of the sequence $ a $ is defined as $a_l\ +\ ...\ +\ a_r$. Niwango wants to know the maximum value of the bitwise AND of the beauty of $ K $ non-empty contiguous subsequences among the possible $ N(N+1)/2 $ non-empty contiguous subsequences (duplicates are allowed among the chosen subsequences).

Please find the maximum value for him.

Input Format

The input is given from the standard input in the following format:

$ N $ $ K $ $ a_1 $ $ a_2 $ $ ... $ $ a_N $

Output Format

Output the answer.

Sample Input and Output

Sample Input #1

4 2
2 5 2 5

Sample Output #1

12

Sample Input #2

8 4
9 1 8 2 7 5 6 4

Sample Output #2

32

Notes/Hints

Constraints

  • $2\ \leq\ N\ \leq\ 1000$
  • $1\ \leq\ a_i\ \leq\ 10^9$
  • $1\ \leq\ K\ \leq\ N(N+1)/2$
  • All numbers given in the input are integers

Sample Explanation 1

There are $ 10 $ different non-empty contiguous subsequences. Enumerating them all, we have:
- Starting from the 1st element: $\{2\},\ \{2,\ 5\},\ \{2,\ 5,\ 2\},\ \{2,\ 5,\ 2,\ 5\}$
- Starting from the 2nd element: $\{5\},\ \{5,\ 2\},\ \{5,\ 2,\ 5\}$
- Starting from the 3rd element: $\{2\},\ \{2,\ 5\}$
- Starting from the 4th element: $\{5\}$

(Note that even if the elements of the sequence are the same, subsequences starting from different indices are considered different.)

The maximum value that can be obtained as the bitwise AND of the beauty of $ 2 $ different subsequences is $ 12 $. This can be achieved by choosing $\{5,\ 2,\ 5\}$ (beauty $ 12 $) and $\{2,\ 5,\ 2,\ 5\}$ (beauty $ 14 $).

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
4 2 2 5 2 5
样例输出
12