The maximum number
Practice
3 (57 votes)
Basic programming
Bit manipulation
Bit manipulation
Math
Sorting
Problem
69% Success 10013 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given an array \(A\) of \(n\) elements \(A_1,A_2,A_3,\ ...,A_n\). Let us define a function \(F(x)=\sum_{i=1}^{n} A_i \& x\).

Note: Here, \(\&\) represents bitwise AND operator.

You are required to find the number of different values of \(x\) for which \(F(x)\) is maximized. There exists a condition for \(x\) that it must have exactly \(l\) bits sets in its binary representation.

Your task is to find a number of such values for which this function is maximized. Print the required number.

If there are infinite such numbers, then print -1.

It can be proved that under the given constraints the value to be printed is either infinite or not greater than 1e18.

Input format

  • The first line contains the number of test cases, \(T\).
  • The second line contains two space-separated integers \(n\) and \(l\) (as described in the problem).
  • The third line contains \(n\) space seprated integers \(A_1,A_2,A_3.....A_n\).

Output format

There are \(T\)lines of the output. The only line of output for each test case contains a single integer as described in the problem statement.

Constraints

\(1\le T\le 1000\)

\(1\le l\le 30\)

\(1\le N\le 20000\)

\(1\le A[i]\le 1e9\)

It is guaranteed that sum of \(N\) over all test cases will not exceed 2e5.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
16 votes
Tags:
AlgorithmsEasyGreedy Algorithms
Points:30
78 votes
Tags:
ApprovedEasyGreedy AlgorithmsMathOpen
Points:30
7 votes
Tags:
EasyGreedy Algorithms