#P9612. Maximizing Group Free Encoding
Maximizing Group Free Encoding
Maximizing Group Free Encoding
Lothar is organizing a rock band concert tour in November. There will be at most one concert per day and every concert must be attended by the full team of musicians. The number of musicians in the tour is fixed. Each candidate musician has a unique schedule for November: for every day labeled L (where L ranges from 1 to 30), if the musician is available that day the day is assigned the number \(2^{30-L}\) (in \(\LaTeX\) format); if not, the day is encoded as 0. Thus, each musician’s schedule code is the sum of the numbers for the days he is free.
For a given group of musicians, the group free encoding is determined similarly: for each day of November, if every musician in the group is free that day, the day contributes \(2^{30-L}\) to the group encoding; otherwise, it contributes 0. In other words, the group free encoding is exactly the bitwise AND of the individual schedule codes (when each schedule is represented in binary with 30 bits).
Lothar’s goal is to choose exactly M musicians from the pool of N candidates (with \(N \ge M\)) to maximize the group free encoding. In this problem, you are given the schedule codes of the candidate musicians, and you need to determine the maximum possible group free encoding over all possible choices of M musicians.
inputFormat
The input consists of two lines. The first line contains two integers N and M (with \(N \ge M\)). The second line contains N integers, each representing the schedule encoding for a candidate musician. Note that each schedule encoding is a number between 0 and \(2^{30}-1\).
outputFormat
Output a single integer representing the maximum possible group free encoding that can be achieved by choosing any group of M musicians.
sample
3 2
7 7 7
7