CF439D.Devu and his Brother

普及/提高-

通过率:0%

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 aa and bb by their father. The array aa is given to Devu and bb to his brother.

As Devu is really a naughty kid, he wants the minimum value of his array aa should be at least as much as the maximum value of his brother's array bb .

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.

输入格式

The first line contains two space-separated integers nn , mm (1<=n,m<=105)(1<=n,m<=10^{5}) . The second line will contain nn space-separated integers representing content of the array aa (1<=ai<=109)(1<=a_{i}<=10^{9}) . The third line will contain mm space-separated integers representing content of the array bb (1<=bi<=109)(1<=b_{i}<=10^{9}) .

输出格式

You need to output a single integer representing the minimum number of operations needed to satisfy Devu's condition.

输入输出样例

  • 输入#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 11 , you can increase a1a_{1} by 11 and decrease b2b_{2} by 11 and then again decrease b2b_{2} by 11 . Now array aa will be [ 33 ; 33 ] and array bb will also be [ 33 ; 33 ]. Here minimum element of aa is at least as large as maximum element of bb . So minimum number of operations needed to satisfy Devu's condition are 33 .

In example 33 , you don't need to do any operation, Devu's condition is already satisfied.

首页