#P2649. Minimum Winning Rounds in Card Game

    ID: 15915 Type: Default 1000ms 256MiB

Minimum Winning Rounds in Card Game

Minimum Winning Rounds in Card Game

John and his friends are playing a special card game. There are \(m\) players (including John) and the deck consists of \(n \times m\) unique cards numbered from \(1\) to \(n\times m\). Each player is dealt exactly \(n\) cards. The game is played in \(n\) rounds; in every round, each player plays one card, and the player who plays the highest card wins the round.

John knows the \(n\) cards in his hand. Assuming that his opponents cooperate to minimize his wins, determine the minimum number of rounds John can win.

Note: In each round, the opponents only need to play one card that is greater than John's played card in order to defeat him. Each card can only be used once.

Hint: Consider the set of cards remaining (i.e. the cards not in John's hand) and use a greedy matching algorithm between John's sorted cards and the opponents' sorted cards.

inputFormat

The input consists of two lines. The first line contains two integers \(m\) and \(n\) separated by a space, where \(m\) is the total number of players and \(n\) is the number of cards each player receives.

The second line contains \(n\) distinct integers representing the cards in John's hand.

outputFormat

Output a single integer, which is the minimum number of rounds John can win if his opponents play optimally.

sample

3 3
2 6 8
0