当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

3375:Network Connection

题目描述

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.

输入解释

The first line contains two integers M (1 ≤ M ≤ 100000), N (1 ≤ N ≤ 2000, NM). 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.

输出解释

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

输入样例
4 2
1
10
12
20
11
15
输出样例
4

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-3375

最后修改于 2020-10-29T07:00:02+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 65536