#P3646. Minimizing Final Beauty in Sculpture Partitioning
Minimizing Final Beauty in Sculpture Partitioning
Minimizing Final Beauty in Sculpture Partitioning
The government of Bali wants to beautify one of the main roads in Bali by partitioning a row of sculptures into contiguous groups. There are N sculptures located along the road, numbered from 1 to N, where the i-th sculpture has an age of Yi years. The government plans to divide these sculptures into exactly X groups, where A ≤ X ≤ B. Each group must contain at least one sculpture and the sculptures in a group must be consecutive.
Once the sculptures are partitioned, the sum of the ages in each group is calculated. The final beauty of the arrangement is defined as the bitwise OR of these group sums. In other words, if the group sums are S1, S2, ..., SX, then the final beauty is:
[ \text{Beauty} = S_{1} \lor S_{2} \lor \dots \lor S_{X}, ]
where the bitwise OR between two non-negative numbers P and Q is defined as follows. Represent P and Q in binary with M bits (where M is the maximum of the two bit-lengths). Let pi and qi be the bits at position i (with the most significant bit at position \(M-1\) and the least significant bit at position 0). Then the bitwise OR is given by:
[ \text{OR}(P, Q) = (p_{M-1} \lor q_{M-1})(p_{M-2} \lor q_{M-2}) \dots (p_1 \lor q_1)(p_0 \lor q_0), ]
Your task is to choose an appropriate partition (with X groups, where A ≤ X ≤ B) so that the final beauty (i.e. the OR over all group sums) is minimized. Compute and output this minimum value.
inputFormat
The first line of input contains three integers: N, A, and B — where N is the number of sculptures, and A and B denote the minimum and maximum number of groups into which sculptures must be divided, respectively.
The second line contains N space-separated integers: Y1, Y2, ..., YN, where Yi represents the age of the i-th sculpture.
outputFormat
Output a single integer — the minimum possible final beauty (i.e. the bitwise OR of the group sums) that can be achieved with an optimal partition.
sample
3 1 2
1 2 3
3
</p>