#C7984. Minimum Possible Threshold
Minimum Possible Threshold
Minimum Possible Threshold
You are given two arrays A
and B
each containing N integers. Your task is to determine the minimum possible threshold T such that the arrays can be reordered to be similar. Two arrays are defined as similar if, after reordering, the sum of the absolute differences between corresponding elements is less than or equal to T.
A natural strategy is to sort both arrays in non-decreasing order. Once sorted, the pairwise absolute differences between the corresponding elements produce the minimum possible total difference. Formally, if the sorted arrays are \(A' = [a'_1, a'_2, \dots, a'_N]\) and \(B' = [b'_1, b'_2, \dots, b'_N]\), then the threshold is computed as:
[ T = \sum_{i=1}^{N} |a'_i - b'_i| ]
Your task is to read the input, compute this minimum threshold, and output the result.
inputFormat
The input is given from stdin in the following format:
- The first line contains a single integer N representing the number of elements in each array.
- The second line contains N space-separated integers representing the array
A
. - The third line contains N space-separated integers representing the array
B
.
outputFormat
Output to stdout a single integer representing the minimum possible threshold \(T\).
## sample3
1 3 5
2 4 6
3