CF1669H.Maximal AND

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Let AND\mathsf{AND} denote the bitwise AND operation, and OR\mathsf{OR} denote the bitwise OR operation.

You are given an array aa of length nn and a non-negative integer kk . You can perform at most kk operations on the array of the following type:

  • Select an index ii ( 1in1 \leq i \leq n ) and replace aia_i with aia_i OR\mathsf{OR} 2j2^j where jj is any integer between 00 and 3030 inclusive. In other words, in an operation you can choose an index ii ( 1in1 \leq i \leq n ) and set the jj -th bit of aia_i to 11 ( 0j300 \leq j \leq 30 ).

Output the maximum possible value of a1a_1 AND\mathsf{AND} a2a_2 AND\mathsf{AND} \dots AND\mathsf{AND} ana_n after performing at most kk operations.

输入格式

The first line of the input contains a single integer tt ( 1t1001 \le t \le 100 ) — the number of test cases. The description of test cases follows.

The first line of each test case contains the integers nn and kk ( 1n21051 \le n \le 2 \cdot 10^5 , 0k1090 \le k \le 10^9 ).

Then a single line follows, containing nn integers describing the arrays aa ( 0ai<2310 \leq a_i < 2^{31} ).

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5 .

输出格式

For each test case, output a single line containing the maximum possible AND\mathsf{AND} value of a1a_1 AND\mathsf{AND} a2a_2 AND\mathsf{AND} \dots AND\mathsf{AND} ana_n after performing at most kk 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 11 ( 212^1 ) of the last 22 elements using the 22 operations, thus obtaining the array [ 22 , 33 , 33 ], which has AND\mathsf{AND} value equal to 22 .

For the second test case, we can't perform any operations so the answer is just the AND\mathsf{AND} of the whole array which is 44 .

首页