#B3745. Card Game Simulation

    ID: 11404 Type: Default 1000ms 256MiB

Card Game Simulation

Card Game Simulation

In this problem, two players, Fusu and Xiao F, are playing a new card game.

Initially, each player holds \(n\) cards. Each card has a suit \(f\) and a point \(p\). In this problem, the suit \(f\) is a positive integer not exceeding \(m\), and the point \(p\) is a positive integer not exceeding \(r\).

The game is played over \(n\) rounds. In each round, Fusu plays one card according to a given order. Then, Xiao F checks his current hand and tries to play a card that satisfies the following conditions:

  • The card has the same suit as Fusu's card.
  • The card's point is greater than Fusu's card's point (i.e. \(p_{XiaoF} > p_{Fusu}\)). Among all such cards, he will choose the one with the smallest point.

If no such card exists, Xiao F will not play a card in that round. Regardless of whether Xiao F plays a card or not, the round ends immediately and the game proceeds to the next round.

Your task is: Given Fusu's play sequence and the initial hand of Xiao F, determine how many cards remain in Xiao F's hand at the end of the game.

Input Format: The first line contains three integers \(n\), \(m\), and \(r\). The next \(n\) lines each contain two integers representing the suit and point of the card played by Fusu in each round. The following \(n\) lines each contain two integers representing the suit and point of each card in Xiao F's initial hand.

Output Format: Output a single integer: the number of cards left in Xiao F's hand after all rounds have been played.

Note: All card values and orders follow the rules described above. All formulas are in \(\LaTeX\) format.

inputFormat

The first line contains three space-separated integers \(n\), \(m\), and \(r\).

The following \(n\) lines each contain two space-separated integers \(f\) and \(p\), representing Fusu's played cards in order.

The next \(n\) lines each contain two space-separated integers \(f\) and \(p\), representing the cards in Xiao F's initial hand.

outputFormat

Output a single integer: the number of cards remaining in Xiao F's hand after all rounds.

sample

3 4 10
1 3
2 5
1 7
1 4
1 8
2 6
0