Optimal Way
Practice
3.2 (4 votes)
Datastructures
Algorithms
Dynamic programming
Introduction to dynamic programming 1
Bitmask
Problem
90% Success 995 Attempts 30 Points 5s Time Limit 256MB Memory 1024 KB Max Code

You are provided an array \(Arr \) of non-negative integers of size \(2*K\). In each round, pick any two integers from the array \(Arr \) (\(number1\) and \(number2\)) and then eliminate both of them. 
The formula for your score in each round is = \(RoundNumber\)\(*( \)\(number1\)\(\&\)\(number2). \)
RoundNumber will start from \(1\) till \(K\), and "\(number1\)\(\&\)\(number2\)" represents bitwise AND of \(number1\) and \(number2 \). The total number of rounds is \(K\). The sum of the scores you will receive in each round will represent your final score. Return the maximum possible final score. 

Input Format:

  • The first line contains an integer \(N\), where \(N\) denotes the size of the array \(Arr\).
  • The second line contains an interger \(K\).

Output Format:

  • Print the maximum possible final score.

Constraints:

  • \(1 \le K \le 10\)
  • \(1 \leq N \leq 20\)
  • \(1 \le Arr[i] \le 10^7\)
  • \(N = 2*K\)

 

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
331 votes
Tags:
Medium
Points:30
10 votes
Tags:
ApprovedBrute-force searchMathMediumOpen
Points:30
11 votes
Tags:
AlgorithmsApprovedCompletedMediumOpen