Task
You are given two arrays and of length and , respectively.
We define the cost of two arrays and of length and as follows:
- For each from to , add to the cost of the two arrays if .
- At the end, add to the cost of the two arrays the value .
Your task is to find the minimum cost of the arrays and if you are allowed to swap any two elements from and (but you cannot change one element from with one element from ) as many times as you want.
Input data
The first line of the input contains two integers, and . The second line contains the array , of length . The third line contains the array , of length .
Output data
The first line of the output will contain a single integer, the minimum cost after performing the swaps in the arrays or .
Constraints and clarifications
- , for
- , for
# | Points | Constraints |
---|---|---|
1 | 40 | |
2 | 60 | No additional constraints |
Example
stdin
4 3
1 1 2 3
2 3 5
stdout
2
Explanation
You swap the pairs and from the array , becoming and the cost becomes , because for each from to , there is only one position where , which is . Therefore, the cost becomes .