## APIO '15 P1 - Bali Sculptures

View as PDF

Points: 25 (partial)
Time limit: 1.0s
Memory limit: 64M

Problem type

The province of Bali has many sculptures located on its roads. Let's focus on one of its main roads.

There are sculptures on that main road, conveniently numbered 1 through consecutively. The age of sculpture is years. To make the road more beautiful, the government wants to partition the sculptures into several groups. Then, the government will plant beautiful trees between the groups, to attract more tourists to Bali.

Here is the rule in partitioning the sculptures:

• The sculptures must be partitioned into exactly groups, where . Each group must consist of at least one sculpture. Each sculpture must belong to exactly one group. The sculptures in each group must be consecutive sculptures on the road.
• For each group, compute the sum of the ages of the sculptures in that group.
• Finally, compute the bitwise OR of the above sums. Let's call this the final beauty value of the partition.

What is the minimum final beauty value that the government can achieve?

Note: the bitwise OR of two non-negative integers and is computed as follows:

• Convert and into binary.
• Let = number of bits of , and = number of bits of . Let .
• Represent in binary as and in binary as , where and are the -th bits of and , respectively. The ()st bits are the most significant bits, while the th bits are the least significant bits.
• OR , in binary, is defined as ( OR )( OR )( OR )( OR ), where
• OR =
• OR =
• OR =
• OR =

#### Input Specification

The first line contains three space-separated integers , , and . The second line contains space-separated integers .

#### Output Specification

A single line containing the minimum final beauty value.

#### Sample Input

6 1 3
8 1 2 1 5 4

#### Sample Output

11

#### Explanation of Sample Output

Partition the sculptures into 2 groups: and . The sums are and . The final beauty value is ( OR ) = .