Bridge Club solution codeforces
There are currentlyhot topics numbered from to at your local bridge club and players numbered from to . Each player holds a different set of views on those topics, more specifically, the -th player holds a positive view on the -th topic if , and a negative view otherwise. Here denotes the bitwise AND operation.
You are going to organize a bridge tournament capable of accommodating at mostpairs of players (bridge is played in teams of two people). You can select teams arbitrarily, but there is one catch: two players cannot be in the same pair if they disagree on or more of those topics, as they would argue too much during the play.
You know that the-th player will pay you dollars if they play in this tournament. Compute the maximum amount of money that you can earn if you pair the players in your club optimally.
The first line contains two integers, ( , ) — the number of hot topics and the number of pairs of players that your tournament can accommodate.
The second line containsintegers ( ) — the amounts of money that the players will pay to play in the tournament.
Print one integer: the maximum amount of money that you can earn if you pair the players in your club optimally under the above conditions.
3 1 8 3 5 7 1 10 3 2
output Bridge Club solution codeforces
2 3 7 4 5 7
3 2 1 9 1 5 7 8 1 1
In the first example, the best we can do is to pair together the-th player and the -nd player resulting in earnings of dollars. Although pairing the -th player with the -th player would give us dollars, we cannot do this because those two players disagree on of the hot topics.
In the second example, we can pair the-th player with the -st player and pair the -nd player with the -rd player resulting in earnings of dollars.