You are given an array A of N integers. The cost of a subarray is defined as the bitwise or value of all its elements. Suppose you split the array into K non-empty subarrays and you compute the sum of their costs. What is the maximum value you can get?
The first line contains two integers N and K.
The second line contains N integers representing array A.
The first line will contain the maximal possible answer.
Input | Output | Explanation |
---|---|---|
5 2 1 4 3 4 8 | 20 | Put the first 2 elements in one subarray and the remaining 3 in the other. The answer will be (A1OR A2)+(A3 OR A4 OR A5)=5+15=20. |