Duel of Cards
InterviewTime limit1sMemory limit2048 MB
Given Alice's n cards out of 2n, find the minimum and maximum number of rounds she can win over all possible deck orders.
- Level
Medium4 of 10
- Topics
- Greedy, Sorting, Two pointers
- Solved
- No attempts yet
Problem
Alice and Bob play a card game with cards numbered uniquely from to . The cards are shuffled and dealt so that each player gets cards. Each player arranges their cards into a deck in any order they choose, face down.
The game has turns. In each turn, both players reveal the top card of their deck and compare the two numbers. The player with the larger card scores one point. This repeats until all cards in both decks have been compared.
After receiving her cards, Alice wants to know the minimum and maximum number of points she may score in the game.
Input
The first line contains a single integer (), the number of cards Alice gets.
Each of the next lines contains one integer between and (inclusive), a card dealt to Alice. All the cards are distinct.
Output
Print two integers: the minimum and the maximum number of points Alice may score.