#P6179. [USACO15DEC] High Card Wins S

[USACO15DEC] High Card Wins S

Description

Bessie is a loyal fan of card games. To her, the other cows are not real opponents. Worse, the other cows’ behavior while playing cards is completely predictable. Even so, Bessie knows that winning is still a challenge.

Bessie and her friend Elsie are playing a card game. The game uses a deck of 2N2N cards numbered from 11 to 2N2N. Bessie and Elsie each receive NN cards. Then they play NN rounds. In each round, Bessie and Elsie each play one card. Whoever plays the card with the larger number wins that round.

Bessie has already predicted Elsie’s playing order. Please help Bessie calculate the maximum number of rounds she can win.

Input Format

The first line contains an integer NN (1N5×1041 \leq N \leq 5 \times 10^4).

The next NN lines each contain one integer. The ii-th line gives the card Elsie plays in round ii. Note that Bessie’s NN cards can be easily determined from the input.

Output Format

Output the maximum number of rounds Bessie can win.

3
1
6
4
2

Hint

Bessie holds the three cards 2,3,52,3,5.

She plays 22 in the first round, 33 in the second round, and 55 in the third round, thus winning rounds 11 and 33. It can be proven that there is no better strategy.

Translated by ChatGPT 5