Exciting Tournament
Time limit1sMemory limit512 MB
Given players with distinct skills and per-player game limits, choose any knockout bracket and report the minimum and maximum total XOR excitement over all games.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Greedy, Sorting, Bit manipulation
- Solved
- No attempts yet
Problem
A group of players compete in a no-holds-barred tournament.
Each player has a unique skill level, represented as an integer. In each game, two players play, and the player with the higher skill level wins. The player with the lower skill level is immediately eliminated from the tournament. The tournament continues until only one player is left.
Due to scheduling constraints, each player has a limit on the maximum number of games they can play. Interestingly, this is the only constraint that the tournament bracket needs to satisfy. In other words, the bracket does not necessarily have the shape of a balanced binary tree, as long as every player plays at most their maximum number of games before being eliminated or winning the entire tournament.
As the tournament organizer, you are free to choose any valid bracket. Given the list of participants, you wonder how exciting (or not exciting) the tournament can get. Concretely, the excitement of a game is defined as the bitwise XOR of the two players' skill levels. The excitement of the tournament is the sum of the excitement of each game.
Compute the minimum and maximum possible excitement values of the entire tournament.
Input
The first line of input contains a single integer (), which is the number of players in the tournament.
Each of the next lines contains two integers () and (). Each line describes a single player; is the skill level of the player, and is the limit on the number of games that player can play.
Output
Output two space-separated integers on a single line, which are the minimum and maximum possible excitement values of the entire tournament, minimum first.