Game of Deletion
Practice
3.1 (14 votes)
Basic programming
Bit manipulation
Bit manipulation
Medium
Medium
Problem
78% Success 2823 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Two players are playing the game of deletion. \(Player1\) plays with array A and \(Player2\) plays with array B. The length of both the arrays are N.
The game is like this - both of them want to delete their respective arrays. A player can delete the array in multiple steps.
During one step, he chooses some numbers from the array and takes the bitwise OR of these numbers and remove these numbers from the array.
This bitwise OR is the cost incurred in deleting the selected numbers. This way he deletes his whole array. The reward of deleting the entire array will be the sum of all numbers in the array minus the sum of the cost of all the steps.
The player with the maximum reward will win.

You have to print the winner along with the \(margin\) of reward he wins with. Let's say \(Player1\) scored \(reward1\) and \(Player2\) scored \(reward2\) and \(Player1\) wins , then the margin will be \(reward1-reward2\).

Input
First line contains a number N . N is the length of the array.
Second line contains the N integers corresponding to elements of the array with \(Player1\).
Third line contains the N integers corresponding to elements of the array with \(Player2\).

Output
If \(Player1\) wins, print 1 followed by a space and then the reward margin he wins with.
If \(Player2\) wins, print 2 followed by a space and then the reward margin he wins with.
Print 1, if the game draws.

Input Constraints
\(1 \le N \le 10^5\)
\(1 \le a[i],b[i] \le10^5\)

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
13 votes
Tags:
Basic ProgrammingBit manipulationMedium
Points:30
17 votes
Tags:
ApprovedBasic ProgrammingBit manipulationMathMedium
Points:30
3 votes
Tags:
Basic ProgrammingBit ManipulationBit manipulationEasyLogic-BasedString Manipulation