Order Capital Round 1 (Codeforces Round 1038, Div. 1 + Div. 2)
C
Manhattan Pairs
Codeforces
1700
原题
← BD →
翻译中…

You are given $n$ points $(x_i, y_i)$ on a 2D plane, where $n$ is even. Select $\tfrac{n}{2}$ disjoint pairs $(a_i, b_i)$ to maximize the sum of Manhattan distances between points in pairs. In other words, maximize $$\sum_{i=1}^{n/2} |x_{a_i} - x_{b_i}| + |y_{a_i} - y_{b_i}|.$$

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains a single even integer $n$ ($2 \leq n \leq 2 \cdot 10^5$) — the number of points.

翻译中…

The $i$-th of the next $n$ lines contains two integers $x_i$ and $y_i$ ($-10^6 \le x_i, y_i \le 10^6$) — the coordinates of the $i$-th point.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output $\tfrac{n}{2}$ lines, the $i$-th line containing two integers $a_i$ and $b_i$ — the indices of points in the $i$-th pair.

翻译中…

If there are multiple solutions, print any of them.

翻译中…

Note

翻译中…

In the first test case, an optimal solution is to select the pairs $(1, 4)$ and $(2, 3)$, which achieves a distance sum of $5 + 3 = 8$.

翻译中…

In the second test case, an optimal solution is to select the pairs $(1, 8)$, $(9, 10)$, $(5, 7)$, $(2, 3)$, $(4, 6)$, which achieves a distance sum of $4 + 7 + 10 + 5 + 7 = 33$.

翻译中…

样例

Input #1
2
4
1 1
3 0
4 2
3 4
10
-1 -1
-1 2
-2 -2
-2 0
0 2
2 -3
-4 -4
-4 -2
0 1
-4 -2
Output #1
4 1
2 3
8 1
9 10
7 5
2 3
6 4
InputCopy OutputCopy
题目信息
题号
2122C
时间限制
2 s
内存限制
256 MB
标签
构造
计算几何
贪心
数学
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。