By Bruno Adami, Universidade de São Paulo - São Carlos Brazil
Given a list of N integers, choose K or more numbers such that the binary AND of them all is maximum. Output that value. For more information about the AND operation see: http://en.wikipedia.org/wiki/Binary_and#AND
The first line contains an integer T (T = 100), that indicates the number of test cases.
For each case, there is a line with the integers N (1 ≤ N ≤ 20* or 1 ≤ N ≤ 35**) and K (1 ≤ K ≤ 7). The following line will contain the N integers of the set, separated with single spaces. The numbers of the set will be between 0 and 230-1, inclusive, and may repeat.
*for around 90% of the cases;
**for the other test cases. The limits are those because 35+7=42 ;)
Output the maximum value for each test case, in a single line.
Sample Input | Sample Output |
3 2 1 10 20 6 3 7 6 2 3 6 7 4 2 1 2 3 3 |
20 6 3 |