No.200 Card Fight!
タグ : / 解いたユーザー数 55
作問者 :
nmnmnmnmnmnmnm
Problem Statement
A game called "Card Fight!" seems to be popular.
Players of this game are called Card Fighters.
First, a Card Fighter holds some number of cards, each with one number written on it.
Then, in each match, each player freely plays one card from their hand, and they compete on which number is larger.
(If the numbers are equal, it is a draw, and there is no winner or loser.)
At each match, a Card Fighter puts the card they used onto the field.
Once a Card Fighter has played all of their cards,
they can collect all the cards they have played onto the field so far and use them again.
A-kun is the King of Card Fighters.
A-kun and C-kun are going to face each other in the final of the "Card Fight!" tournament.
As the King of Card Fighters, A-kun really wants to win as many times as possible against C-kun.
(Only the number of wins matters; the numbers of draws and losses do not.)
When A-kun brought this up with C-kun, C-kun readily agreed to let A-kun win.
A-kun discussed with C-kun the order in which they would play their cards so that he could win more matches.
Both A-kun and C-kun decided the order of playing their cards so that the number of A-kun's wins would be maximized.
At most how many matches can A-kun win against C-kun?
Input
$N$ $A$ $B_1$ $B_2$ $\dots$ $B_A$ $C$ $D_1$ $D_2$ $\dots$ $D_C$
$N$ is the number of matches. $1 \le N \le 50$.
$A$ is the number of cards A-kun has. $1 \le A \le 50$.
$B_i$ is the number of the $i$-th card A-kun has. $1 \le B_i \le 100$.
$C$ is the number of cards C-kun has. $1 \le C \le 50$.
$D_i$ is the number of the $i$-th card C-kun has. $1 \le D_i \le 100$.
Output
Output on one line the number of A-kun's wins when A-kun and C-kun arrange the order of playing their cards so that A-kun wins as many matches as possible.
Do not forget the newline at the end.
Sample
Sample 1
Input
3 2 2 3 3 1 2 3
Output
2
A-kun and C-kun play 3 matches.
A-kun has 2 cards: 2 and 3.
C-kun has 3 cards: 1, 2, and 3.
A-kun plays his cards in the order 2, 3; when he runs out of cards, he collects the cards 2 and 3, and then plays the card 3.
C-kun plays his cards in the order 3, 2, 1.
A-kun loses the first match but can win the second and third matches.
A-kun can win 2 matches.
Sample 2
Input
10 3 2 2 2 4 3 3 3 3
Output
0
A-kun and C-kun play 10 matches.
A-kun has 3 cards with the number 2.
C-kun has 4 cards with the number 3.
No matter how A-kun and C-kun arrange the order of playing their cards, A-kun cannot win a single match against C-kun.
Sample 3
Input
7 3 4 5 6 6 1 2 3 4 5 10
Output
6
For example, A-kun plays his cards in the order 4,5,6,5,6,4,6.
Meanwhile, C-kun plays his cards in the order 1,2,3,4,5,10,1.
In this case, A-kun can win 6 out of the 7 matches.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。