No.2523 Trick Flower
タグ : / 解いたユーザー数 33
作問者 :
MasKoaTS
/ テスター :
fky_
Problem Statement
The magician Koa has flowers of $N$ colors numbered $1, 2, \dots, N$, with $A_{1}, A_{2}, \dots, A_{N}$ flowers of each color, respectively.
Koa performs the following operation on them any number of times, $0$ or more.
Choose $1$ integer $i$ between $1$ and $N$, inclusive, and do the following.
If Koa has at least $1$ flower of color $C_{i}$, change the color of any $1$ of those flowers to color $i$ by magic.
After finishing all of the above operations, Koa performs the following operation $0$ or more times, for as long as possible.
Use $B_{1}, B_{2}, \dots, B_{N}$ flowers of colors $1, 2, \dots, N$, respectively, to make $1$ bouquet.
However, the same flower cannot be used for multiple bouquets.
What is the maximum number of bouquets Koa can make?
Constraints
$1 \leq N \leq 10^{5}$
$0 \leq A_{i}, B_{i} \leq 10^{9}$ $(1 \leq i \leq N)$
The sum of $B_{1}, B_{2}, \dots, B_{N}$ is at least $1$
$1 \leq C_{i} \leq N$ $(1 \leq i \leq N)$
All input values are integers
Input
The input is given in the following format.
$N$
$A_{1}$ $A_{2}$ $\cdots$ $A_{N}$
$B_{1}$ $B_{2}$ $\cdots$ $B_{N}$
$C_{1}$ $C_{2}$ $\cdots$ $C_{N}$
Line $1$ contains $N$
Line $2$ contains $A_{1}, A_{2}, \dots, A_{N}$ in this order, separated by single-byte spaces
Line $3$ contains $B_{1}, B_{2}, \dots, B_{N}$ in this order, separated by single-byte spaces
Line $4$ contains $C_{1}, C_{2}, \dots, C_{N}$ in this order, separated by single-byte spaces
Output
Print the answer on $1$ line.
Sample
Sample 1
Input
3 9 3 1 1 2 3 2 1 1
Output
2
By performing the following operations, $2$ bouquets can be made.
Let $i = 2$. Choose $1$ flower of color $1$ and change it to color $2$.
Let $i = 3$. Choose $1$ flower of color $1$ and change it to color $3$. Repeat this operation a total of $5$ times.
After the previous $2$ operations, the numbers of flowers of colors $1, 2, 3$ are $3, 4, 6$, respectively.
Use $1, 2, 3$ flowers of colors $1, 2, 3$, respectively, to make $1$ bouquet. Repeat this operation a total of $2$ times.
No matter how the operations are performed, it is impossible to make $3$ or more bouquets.
Sample 2
Input
2 0 100 100 0 1 1
Output
0
Not even $1$ bouquet can be made.
Sample 3
Input
12 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 1
Output
12000000000
The answer may not fit in a 32-bit integer type.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。