#C9401. Minimize Teleportation Distance
Minimize Teleportation Distance
Minimize Teleportation Distance
In this problem, there are ( M ) scientists and ( M ) laboratories located on a one-dimensional number line. The coordinates of the scientists are given in array ( c ), and the coordinates of the laboratories are given in array ( d ). Your task is to assign each scientist to a unique laboratory such that the total teleportation distance, defined as the sum of the absolute differences between a scientist's coordinate and its assigned laboratory's coordinate, is minimized.
It can be shown that by sorting the coordinates of scientists and laboratories, pairing them in order minimizes the total distance. Under these conditions, there is exactly one way to achieve this minimal distance. You should output the number of ways to obtain the minimal total teleportation distance modulo (10^9+7).
inputFormat
The input is read from standard input (stdin) and consists of three lines:
- The first line contains a single integer ( M ), representing the number of scientists (and laboratories).
- The second line contains ( M ) space-separated integers representing the coordinates of the scientists.
- The third line contains ( M ) space-separated integers representing the coordinates of the laboratories.
It is guaranteed that ( M \geq 1 ).
outputFormat
Print a single integer — the number of ways to assign the scientists to laboratories such that the total teleportation distance is minimized, taken modulo (10^9+7).## sample
2
1 4
3 2
1