Maximizing expressions
Practice
3.2 (33 votes)
Basic programming
Bit manipulation
Bit manipulation
Medium
Observation
Problem
19% Success 5902 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given three arrays \(A, B,\ and\ C\). All the three arrays consist of \(N\) integers.

You must perform the following operation on each index exactly one time:

\(Convert(i)\): Select a positive value \(D\) such that \(C_i\ \&\ D = D\), and update \(B_i = B_i \oplus D\).

Here, \(\oplus\) and \(\&\) denotes the bitwise XOR operation and bitwise AND operation.

You are required to maximize the following expression:

\(S = \sum_{i=1}^{n} A_i \oplus B_i\)    

Input format

  • First line: A single integer \(N\) denoting the number of elements of the array
  • Next line: \(N\) integers of array \(A\)
  • Next line: \(N\) integers of array \(B \)
  • Next line: \(N\) integers of array \(C\)

Output format
Print a single integer that denotes the maximum value of \(S\).

Constraints
\(1 \leq N \leq 10^5\)

\(1 \leq A_i, B_i, C_i < 2^{30}\)

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
346 votes
Tags:
Bit ManipulationBit manipulationDynamic ProgrammingMedium
Points:30
3 votes
Tags:
Bit ManipulationGreedy algorithmBasic ProgrammingBitmaskBasics of Bit Manipulation
Points:30
11 votes
Tags:
ArraysBasic ProgrammingBit ManipulationBit manipulationJavaMediumPython