Maximum OR
Practice
3 (10 votes)
Bit manipulation
Basic programming
Basics of bit manipulation
Algorithms
Problem
69% Success 2089 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given an array $$A$$ containing $$N$$ integers. You can do the following operation at most $$K$$ times:

  • Choose any index $$i$$ and increase the value of $$A_i$$ by $$1$$.

Your task is to find the maximum bitwise OR of the array.

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$$.

Output format

For each test case, print the maximum possible bitwise OR of the array after performing at most $$K$$ operations in a new line.

Constraints

\(1 \le T \le 100000\\ 1 \le N \le 200000\\ 0 \le K \le 1e18\\ 0 \le A_i \le 2^{60}\)

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
20 votes
Tags:
Bit ManipulationBasic ProgrammingBasics of Bit Manipulation
Points:30
69 votes
Tags:
Bit ManipulationBasic ProgrammingBasics of bit manipulationXORBasics of Bit Manipulation
Points:30
67 votes
Tags:
Basic ProgrammingBit Manipulation
Editorial

Login to unlock the editorial