CF439D.Devu and his Brother
普及+/提高
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays a and b by their father. The array a is given to Devu and b to his brother.
As Devu is really a naughty kid, he wants the minimum value of his array a should be at least as much as the maximum value of his brother's array b.
Now you have to help Devu in achieving this condition. You can perform multiple operations on the arrays. In a single operation, you are allowed to decrease or increase any element of any of the arrays by 1. Note that you are allowed to apply the operation on any index of the array multiple times.
You need to find minimum number of operations required to satisfy Devu's condition so that the brothers can play peacefully without fighting.
德武和他的弟弟彼此非常喜爱。由于他们都是超级极客,所以只喜欢玩数组。他们的父亲给了他们两个数组 a 和 b:数组 a 给了德武,数组 b 给了他的弟弟。
由于德武是个非常淘气的孩子,他希望自己的数组 a 的最小值至少要达到他弟弟的数组 b 的最大值。
现在你需要帮助德武达成这一条件。你可以对这两个数组执行多次操作。在一次操作中,你被允许将任意一个数组中的任意一个元素增加或减少 1。注意:你可以对数组中任意下标位置的元素执行多次该操作。
你需要求出满足德武条件所需的最少操作次数,以便兄弟俩能和平玩耍、不吵架。
输入格式
The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 105). The second line will contain n space-separated integers representing content of the array a (1 ≤ a__i ≤ 109). The third line will contain m space-separated integers representing content of the array b (1 ≤ b__i ≤ 109).
第一行包含两个以空格分隔的整数 n、m(1 ≤ n, m ≤ 105)。
第二行包含 n 个以空格分隔的整数,表示数组 a 的内容(1 ≤ ai ≤ 109)。
第三行包含 m 个以空格分隔的整数,表示数组 b 的内容(1 ≤ bi ≤ 109)。
输出格式
You need to output a single integer representing the minimum number of operations needed to satisfy Devu's condition.
你需要输出一个整数,表示满足 Devu 条件所需的最少操作次数。
输入输出样例
输入#1
2 2 2 3 3 5
输出#1
3
输入#2
3 2 1 2 3 3 4
输出#2
4
输入#3
3 2 4 5 6 1 2
输出#3
0
说明/提示
In example 1, you can increase _a_1 by 1 and decrease _b_2 by 1 and then again decrease _b_2 by 1. Now array a will be [3; 3] and array b will also be [3; 3]. Here minimum element of a is at least as large as maximum element of b. So minimum number of operations needed to satisfy Devu's condition are 3.
In example 3, you don't need to do any operation, Devu's condition is already satisfied.
在示例 1 中,你可以将 a1 增加 1,并将 b2 减少 1,然后再将 b2 减少 1。此时数组 a 将变为 [3; 3],数组 b 也将变为 [3; 3]。此时 a 的最小元素至少与 b 的最大元素一样大。因此,满足 Devu 条件所需的最少操作次数为 3。
在示例 3 中,你无需执行任何操作,Devu 的条件已经满足。
输入解题思路,AI测评打分。不知道怎么写?