QOJ.ac

QOJ

时间限制: 1.0 s 内存限制: 256 MB 总分: 100 可 Hack ✓

#14095. Max Pair Matching

统计

给你 $2n$ 个整数对 $(a_i, b_i)$。考虑一个含有 $2n$ 个顶点的完全图,定义边 $(i, j)$ 的权重为 $w_{ij} = \max(|a_i - a_j|, |a_i - b_j|, |b_i - a_j|, |b_i - b_j|)$。

求该图的最大权匹配。

换句话说,考虑所有在该图中选择 $n$ 条边且任意两条选择的边没有公共端点的方法。这些边的最大可能总权重是多少?

输入格式

输入的第一行包含一个整数 $n$ ($1 \le n \le 10^5$)。

接下来的 $2n$ 行中,第 $i$ 行包含两个整数 $a_i$ 和 $b_i$ ($0 \le a_i, b_i \le 10^9$)。

输出格式

输出一个整数,表示该图的最大权匹配。

样例

输入格式 1

2
0 10
7 7
9 4
2 15

输出格式 1

18

说明

邻接矩阵:

0 7 9 15
7 0 3 8
9 3 0 11
15 8 11 0

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.