#P6288. [COCI 2016/2017 #1] Kralj
[COCI 2016/2017 #1] Kralj
Description
A war is about to break out between the Dwarven Kingdom and the Elven Kingdom! The elven king Slavko numbers elves as . The dwarf king Mirko makes dwarves stand in a circle, and starting from some dwarf, numbers them clockwise as .
Next, Mirko assigns each elf a number , meaning the number of the dwarf that elf will duel. However, due to his carelessness, different elves may be assigned the same number.
To make the duels fair, both sides decide:
- Slavko chooses an elf who has not yet been assigned an opponent, and let its number be .
- If the dwarf numbered has not yet been assigned an opponent, then that dwarf becomes this elf’s opponent. Otherwise, starting from the dwarf numbered , choose the first dwarf clockwise along the circle who has not yet been assigned an opponent as this elf’s opponent.
- Repeat the above steps until all dwarves and elves have been assigned opponents.
Slavko has collected the strength values of all dwarves and elves. In a duel, the side with the greater strength value always wins. He wants to know: by planning the order in which he chooses elves, what is the maximum number of elves that can win their duels?
Input Format
The first line contains an integer .
The second line contains integers .
The third line contains integers , where is the strength value of dwarf .
The fourth line contains integers , where is the strength value of elf .
Output Format
One line with one integer, the maximum number of elves that can win their duels.
3
2 3 3
4 1 10
2 7 3
2
4
3 1 3 3
5 8 7 10
4 1 2 6
1
3
1 2 3
8 4 3
9 2 6
2
Hint
Explanation for Sample 1
Slavko chooses elves in the order .
Then, the opponents of elves are dwarves , respectively.
Elves and will win their duels.
Constraints
For of the testdata, , , .
Note
This problem is translated from COCI2016-2017 CONTEST #1 T5 Kralj.
Translated by ChatGPT 5
京公网安备 11011102002149号