编程介的小学生 2017-05-13 14:47 采纳率: 20.5%
浏览 832
已采纳

Network Connection

Description

There are M network interfaces in the wall of aisle of library. And N computers next to the wall need to be connected to the network. A network interface can only connect with one computer at most. To connect an interface with coordinate x with a computer with coordinate y needs |x - y| unit of length of network cable. Your task is to minimize the total length of network cables to be used.

Input

The first line contains two integers M (1 ≤ M ≤ 100000), N (1 ≤ N ≤ 2000, N ≤ M). The following M + N lines each contains a integer coordinate. The first M coordinates are corresponding to the network interfaces, and the next N ones corresponding to the computers. All coordinates are arranged in [0, 1000000]. Distinct interfaces may have the same coordinate, so do the computers.

Output

Print an integer, representing minimum length of network cables to be used.

Sample Input

4 2
1
10
12
20
11
15
Sample Output

4

  • 写回答

1条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题