#4611. [UOI 2025] Manhattan Pairing

    ID: 4611 传统题 2500ms 256MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>P12548动态规划 DP贪心二分2025UOI(乌克兰)

[UOI 2025] Manhattan Pairing

[UOI 2025] Manhattan Pairing

题目描述

For a pair of points on the Cartesian plane $(x_1, y_1)$ and $(x_2, y_2)$, we define the *Manhattan distance* between them as $|x_1-x_2|+|y_1-y_2|$. For example, for the pair of points $(4, 1)$ and $(2, 7)$, the *Manhattan distance* between them is $|4-2|+|1-7| = 2+6 = 8$.

You are given 2⋅n2 \cdot n points on the Cartesian plane, whose coordinates are integers. All yy-coordinates of the given points are either 00 or 11.

Split the given points into nn pairs such that each of these points belongs to exactly one pair, and the maximum Manhattan distance between the points of one pair is minimized.

输入格式

The first line contains a single integer $n$ $(1 \le n \le 10^5)$.

In the following 2⋅n2 \cdot n lines, each line contains two integers xix_i and yiy_i (0≤xi≤109,0≤yi≤1)(0 \le x_i \le 10^9, 0 \le y_i \le 1) --- the coordinates of the corresponding point.

输出格式

Output a single integer --- the maximum *Manhattan distance* between the points of one pair in the optimal partition.
1
3 1
1 0
3
3
18 0
3 0
1 0
10 0
8 0
14 0
4
4
3 0
0 1
5 0
2 1
6 0
3 0
5 1
2 1
2

提示

In the second example, the pairing $[(18, 0), (14, 0)]$, $[(3, 0), (1, 0)]$, and $[(8, 0), (10, 0)]$ is the only optimal partition. The *Manhattan distances* between the points of one pair in this partition are $4$, $2$, and $2$, respectively.

In the third example, the pairing [(0,1),(2,1)][(0, 1), (2, 1)], [(2,1),(3,0)][(2, 1), (3, 0)], [(3,0),(5,0)][(3, 0), (5, 0)], and [(5,1),(6,0)][(5, 1), (6, 0)] is an optimal partition. All Manhattan distances between the points of one pair in this partition are equal to 22.

Illustration for the third example

Scoring

  • (22 points): n=1n = 1;
  • (33 points): xi=0x_i = 0 for 1≤i≤2⋅n1 \le i \le 2\cdot n;
  • (44 points): n≤4n \le 4;
  • (1111 points): n≤10n \le 10;
  • (1414 points): yi=0y_i = 0 for 1≤i≤2⋅n1 \le i \le 2\cdot n;
  • (1010 points): xi≠xjx_i \neq x_j for 1≤i<j≤2⋅n1 \le i < j \le 2\cdot n;
  • (2929 points): n≤1000n \le 1000;
  • (2727 points): no additional restrictions. 标签: P12548|动态规划 DP|贪心|二分|2025|UOI(乌克兰)

来源

P12548|[UOI 2025] Manhattan Pairing