#C3940. Minimum Array Length after Bitwise AND Operations
Minimum Array Length after Bitwise AND Operations
Minimum Array Length after Bitwise AND Operations
You are given an array of (n) integers and an integer (k). In one operation, you can choose any contiguous subarray and replace it with a single number equal to the bitwise AND of all its elements. Formally, if you select a subarray (a_l, a_{l+1}, \dots, a_r), it is replaced by a single integer (a_l \land a_{l+1} \land \cdots \land a_r), where (\land) denotes the bitwise AND operation. This operation reduces the array's length by (r-l). You are allowed to perform at most (k) such operations. Your task is to determine the minimum possible length of the array after performing at most (k) operations.
Note: It can be observed that the answer is always (\max(1, n - k)), as each operation reduces the length by at most 1 and the array length cannot drop below 1.
inputFormat
The input is given via standard input. The first line contains a single integer (T), the number of test cases. Each test case consists of two lines. The first line contains two space-separated integers (n) and (k), representing the length of the array and the maximum number of operations you can perform, respectively. The second line contains (n) space-separated integers representing the elements of the array.
outputFormat
For each test case, output a single integer on a new line --- the minimum possible length of the array after performing at most (k) operations.## sample
3
5 2
3 5 1 9 14
6 3
4 6 2 8 4 7
4 1
1 1 1 1
3
3
3
</p>