#C11542. Maximum Bitwise AND of K Elements
Maximum Bitwise AND of K Elements
Maximum Bitwise AND of K Elements
Given an array of n integers and an integer k, your task is to choose exactly k elements from the array such that the bitwise AND of these elements is maximized.
The bitwise AND operation for a set of numbers \(a_1, a_2, \dots, a_k\) is defined as:
[ a_1 ;&; a_2 ;&; \dots ;&; a_k ]
You should read the input from stdin and print the result to stdout. It is guaranteed that the size of the input will be small enough to allow a brute-force solution.
inputFormat
The input is given in two lines:
- The first line contains two integers, \(n\) and \(k\), where \(n\) is the number of elements in the array and \(k\) is the number of elements to select.
- The second line contains \(n\) space-separated integers representing the array.
outputFormat
Output a single integer to stdout representing the maximum bitwise AND value obtained by choosing exactly \(k\) elements from the array.
## sample5 3
6 4 7 8 1
4
</p>