Maximum utility
Practice
3.2 (6 votes)
Basic programming
Bit manipulation
Basics of bit manipulation
Algorithms
Greedy algorithms
Bit manipulation
Problem
87% Success 817 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given an array $$A$$ containing $$N$$ integers. The \(i^{th}\) integer is \(A_i\) and has a utility of \(B_i\). You select a combination of integers whose bitwise OR is less than or equal to \(K\)

You are required to make the sum of utilities of selected integers to be as large as possible.

Input format

  • The first line contains an integer $$T$$ denoting the number of test cases.
  • The first line of each test case contains two space-separated integers $$N$$ and $$K$$.
  • The second line of each test case contains $$N$$ space-separated integers denoting array $$A$$.
  • The third line of each test case contains $$N$$ space-separated integers denoting array $$B$$.

Output format

For each test case, print the maximum possible sum of utilities of selected integers in a new line.

Constraints

\(1 \le T \le 1000\\ 1 \le N \le 200000\\ 0 \le K,A_i,B_i < 2^{30}\)

It is guaranteed that the sum of $$N$$ over $$T$$ test cases does not exceed $$1e6$$.

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
3 votes
Tags:
Bit ManipulationGreedy algorithmBasic ProgrammingBitmaskBasics of Bit Manipulation
Points:30
6 votes
Tags:
Bit ManipulationBasics of Bit ManipulationBasic ProgrammingObservationMathImplementation
Points:30
9 votes
Tags:
Bit manipulationBit ManipulationBasics of Bit ManipulationBasic Programming