$n$ boys and $m$ girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from $1$ to $n$ and all girls are numbered with integers from $1$ to $m$. For all $1≤i≤n$ the minimal number of sweets, which $i$-th boy presented to some girl is equal to $b_i$ and for all $1≤j≤m$ the maximal number of sweets, which $j$-th girl received from some boy is equal to $g_j$.
More formally, let $a_{i,j}$ be the number of sweets which the $i$-th boy give to the $j$-th girl. Then $b_i$ is equal exactly to the minimum among values $a_{i,1}$,$a{i,2}$,…,$a_{i,m}$ and $g_j$ is equal exactly to the maximum among values $b_{1,j}$,$b_{2,j}$,…,$b_{n,j}$.
You are interested in the minimum total number of sweets that boys could present, so you need to minimize the sum of $a_{i,j}$ for all $(i,j)$ such that $1≤i≤n$ and $1≤j≤m$. You are given the numbers $b_1$,…,$b_n$ and $g_1$,…,$g_m$, determine this number.



最后更新: 2019年06月12日 23:21


× 请我吃糖~