Integer distribution
Practice
2.6 (14 votes)
Algorithms
Bit manipulation
Dynamic programming
Medium
Problem
86% Success 3404 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given a list \(A\) of \(N\) integers. Here, \(N\) is an even number. These integers must be distributed into \(N/2\) pairs and the power of each of the pairs is added.
The power of a pair \(P(i,j)\) consisting of the \(i^{th}\) and \(j^{th}\) number is defined as the XOR of the two numbers \(A[i]\) and \(A[j]\).
Write a program to determine the minimum and the maximum possible sum of the \(N/2\) pairs.

Input format

  • First line: An integer \(N\)
  • Next \(N\) lines: An integer where each denotes an element of the list

Output format

The output consists of two space-separated integers. The first is the minimum possible sum and the second is the maximum possible sum.

Constraints

\(1 \le N \le 20; N \ is \ even\)
\( A[i] \) fits in \(32-bit\) integer value.

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
27 votes
Tags:
AlgorithmsDynamic ProgrammingMedium
Points:30
47 votes
Tags:
AlgorithmsApprovedBit ManipulationDynamic ProgrammingMediumReady
Points:30
31 votes
Tags:
AlgorithmsApprovedBit ManipulationDynamic ProgrammingMediumOpen