#P11058. 合并香蕉

合并香蕉

Background

Problem Description

There are nn bananas. The ii-th banana can be simplified as a positive integer pair (ai,ki)(a_i,k_i), where 2ki102\le k_i\le 10.

Initially, there are nn piles of bananas, and the ii-th pile contains only the ii-th banana.

Each time, you may choose two different piles to merge. During a merge, the sizes of bananas will be reduced.

Specifically, if the ii-th banana participates in a merge, then its size aia_i becomes 1ki\frac{1}{k_i} of its original value.

Participates in a merge: before merging, it is in one of the two piles being merged.

You want to merge all bananas into one pile. Since bigger bananas are better, you need to make the sum of all aia_i after all operations as large as possible.

Considering that finding the optimal solution may be difficult, you only need to get as close to the standard answer as possible. See the Scoring section for details.

To prevent you from outputting a random number, you also need to output a plan. See the Output Format section for details.

Input Format

The first line contains one positive integer nn.

The next nn lines each contain two positive integers ai,kia_i,k_i.

Output Format

Output n1n-1 lines. Each line contains two numbers x,yx,y, meaning to merge pile xx and pile yy.

For the ii-th merge, denote the newly formed pile as pile n+in+i. The two original piles (pile xx and pile yy) will henceforth be considered nonexistent, so you are not allowed to use xx and yy in later merges. Otherwise, you will get zero points.

3
1 10
27 3
32 2
1 2
4 3

Hint

Sample Explanation

For the sample, the given output corresponds to ending with a=(0.01,3,16)a=(0.01,3,16), and the sum of aia_i is 19.0119.01.

Also, if you output the following, then it ends with a=(0.01,9,8)a=(0.01,9,8), and the sum of aia_i is 17.0117.01, which can get 44 points.

1 3
2 4

Scoring

For each test point, scoring is done as follows:

  • If your output is invalid, you get 00 points.
  • Otherwise, let ff be the sum of aia_i after all operations for your output plan, and let ansans be the sum of aia_i after all operations for the standard answer’s plan. Your score is $s=\lfloor \max\{0,10-\log_{10} \max\{1,\frac{ans-f}{\epsilon}\}\}\rfloor$ points, where ϵ=105\epsilon=10^{-5}.

Constraints

This problem has 1010 test points, each worth 1010 points.

Test Point ID n=n= Special Property
11 33 None
22 55
33 1010
44 2020
55 100100
66 10310^3
77 105310^5-3 ai=1a_i=1 and ki=2k_i=2
88 105210^5-2 ai=1a_i=1
99 105110^5-1 ki=2k_i=2
1010 10510^5 None

For all data, it is guaranteed that 3n1053\le n\le 10^5, 1ai1051\le a_i\le 10^5, and 2ki102\le k_i\le 10.

Translated by ChatGPT 5