Bali Sculptures
Time limit1sMemory limit64 MB
Split N sculptures in order into between A and B consecutive groups to minimize the bitwise OR of the group age sums.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Greedy, Bit manipulation
- Solved
- No attempts yet
Problem
A main street in Bali has sculptures on it, numbered 1 to in order along the street. Sculpture is years old, that is, it was made years ago. To make the street prettier, the government wants to split the sculptures into groups and plant trees between neighbouring groups.
The rules for splitting the sculptures are:
- The sculptures are split into exactly groups, where . Every group holds at least one sculpture, and every sculpture belongs to exactly one group. The sculptures of one group must be consecutive along the street.
- For each group, add up the ages of the sculptures in that group.
- Take the bitwise OR of all the group sums. That value is the beauty of the split.
Find the smallest beauty that a valid split can reach.
The bitwise OR of two non-negative integers and is computed like this. Write both numbers in binary and pad the shorter one with leading zeros so that the two lengths match. Each bit of the result is decided by the two bits in the same position:
- 0 OR 0 = 0
- 0 OR 1 = 1
- 1 OR 0 = 1
- 1 OR 1 = 1
Input
The first line contains the integers , and , separated by spaces. The second line contains the ages , separated by spaces.
- If is greater than 100, then .
Output
Print the minimum possible beauty on a single line.
Hint
In the first example the sculptures are split into (8 1 2) and (1 5 4). The group sums are 11 and 10, and their bitwise OR is 11.