AtCoder Beginner Contest 181
E
Transformable Teacher
AtCoder
⌀ 1193
原题
← DF →
翻译中…

Problem Statement

翻译中…

There are $N$ children in a kindergarten. The height of the $i$-th child is $H_i$. Here, $N$ is an odd number.

翻译中…

You, the teacher, and these children - $N+1$ people in total - will make $\large\frac{N+1}2$ pairs.

翻译中…

Your objective is to minimize the sum of the differences in height over those pairs. That is, you want to minimize $\displaystyle \sum_{i=1}^{(N+1)/2}|x_i-y_i|$, where $(x_i, y_i)$ is the pair of heights of people in the $i$-th pair.

翻译中…

You have $M$ forms that you can transform into. Your height in the $i$-th form is $W_i$.

翻译中…

Find the minimum possible sum of the differences in height over all pairs, achieved by optimally choosing your form and making pairs.

翻译中…

Constraints

翻译中…
  • All values in input are integers.
  • $1 \leq N, M \leq 2 \times 10^5$
  • $N$ is an odd number.
  • $1 \leq H_i \leq 10^9$
  • $1 \leq W_i \leq 10^9$
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N M
H_1 \dots H_N
W_1 \dots W_M

翻译中…

Output

翻译中…

Print the minimum possible sum of the differences in height over all pairs, achieved by optimally choosing your form and making pairs.

翻译中…

样例

Input #1
5 3
1 2 3 4 7
1 3 8
Output #1
3
The minimum is minimized by choosing the form with the height $8$ and making pairs with heights $(1, 2)$, $(3, 4)$, and $(7, 8)$.
Input #2
7 7
31 60 84 23 16 13 32
96 80 73 76 87 57 29
Output #2
34
Input #3
15 10
554 525 541 814 661 279 668 360 382 175 833 783 688 793 736
496 732 455 306 189 207 976 73 567 759
Output #3
239
题目信息
题号
abc181_e
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。