CF439D Devu and his Brother
Description
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.
Input Format
N/A
Output Format
N/A
Explanation/Hint
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.