There are no heroes in this problem. I guess we should have named it "To Zero".
You are given two arrays $$$a$$$ and $$$b$$$, each of these arrays contains $$$n$$$ non-negative integers.
Let $$$c$$$ be a matrix of size $$$n \times n$$$ such that $$$c_{i,j} = |a_i - b_j|$$$ for every $$$i \in [1, n]$$$ and every $$$j \in [1, n]$$$.
Your goal is to transform the matrix $$$c$$$ so that it becomes the zero matrix, i. e. a matrix where every element is exactly $$$0$$$. In order to do so, you may perform the following operations any number of times, in any order:
You have to calculate the minimum number of coins required to transform the matrix $$$c$$$ into the zero matrix. Note that all elements of $$$c$$$ should be equal to $$$0$$$ simultaneously after the operations.
The first line contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$).
The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^8$$$).
The third line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$0 \le b_j \le 10^8$$$).
Print one integer — the minimum number of coins required to transform the matrix $$$c$$$ into the zero matrix.
3 1 2 3 2 2 2
2
3 3 1 3 1 1 2
5
2 1 0 2 1
2
2 1 4 2 3
4
4 1 3 3 7 6 9 4 2
29
In the first example, the matrix looks as follows:
1 | 1 | 1 |
0 | 0 | 0 |
1 | 1 | 1 |
You can turn it into a zero matrix using $$$2$$$ coins as follows:
In the second example, the matrix looks as follows:
2 | 2 | 1 |
0 | 0 | 1 |
2 | 2 | 1 |
You can turn it into a zero matrix using $$$5$$$ coins as follows:
Name |
---|