CF1669H.Maximal AND
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let AND denote the bitwise AND operation, and OR denote the bitwise OR operation.
You are given an array a of length n and a non-negative integer k . You can perform at most k operations on the array of the following type:
- Select an index i ( 1≤i≤n ) and replace ai with ai OR 2j where j is any integer between 0 and 30 inclusive. In other words, in an operation you can choose an index i ( 1≤i≤n ) and set the j -th bit of ai to 1 ( 0≤j≤30 ).
Output the maximum possible value of a1 AND a2 AND … AND an after performing at most k operations.
输入格式
The first line of the input contains a single integer t ( 1≤t≤100 ) — the number of test cases. The description of test cases follows.
The first line of each test case contains the integers n and k ( 1≤n≤2⋅105 , 0≤k≤109 ).
Then a single line follows, containing n integers describing the arrays a ( 0≤ai<231 ).
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105 .
输出格式
For each test case, output a single line containing the maximum possible AND value of a1 AND a2 AND … AND an after performing at most k operations.
输入输出样例
输入#1
4 3 2 2 1 1 7 0 4 6 6 28 6 6 12 1 30 0 4 4 3 1 3 1
输出#1
2 4 2147483646 1073741825
说明/提示
For the first test case, we can set the bit 1 ( 21 ) of the last 2 elements using the 2 operations, thus obtaining the array [ 2 , 3 , 3 ], which has AND value equal to 2 .
For the second test case, we can't perform any operations so the answer is just the AND of the whole array which is 4 .