Wiring

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

Maryam is an electrical engineer. She is designing wiring on a communication tower. On the tower there are some connection points, placed at distinct heights. A wire can be used to connect any two connection points. Each connection point can be connected to an arbitrary number of wires. There are two types of connection points: red and blue.

For the purpose of this problem the tower should be viewed as a line and the connection points as blue and red points that are at non-negative integer coordinates on this line. The length of a wire is the distance between the two connection points it connects.

Your goal is to help Maryam find a wiring scheme such that:

  1. Each connection point has at least one wire to a connection point of a different color.
  2. The total length of the wires is minimized.

제한

  • 1n,m100,0001 \leq n, m \leq 100\\,000,
  • 0r\[i]1090 \leq r\[i] \leq 10^9 (for all 0in10 \leq i \leq n-1),
  • 0b\[i]1090 \leq b\[i] \leq 10^9 (for all 0im10 \leq i \leq m-1),
  • Each of the arrays rr and bb is sorted in ascending order.
  • All n+mn+m values in the arrays rr and bb are distinct.