#P10466. 邻值查找

邻值查找

Problem Description

Given a sequence AA of length nn, all numbers in AA are distinct.

For each number AiA_i in AA, find:

min1j<iAiAj\min_{1 \le j < i} |A_i - A_j|

and the index jj that makes the above expression reach its minimum (denoted as PiP_i). If the minimum is not unique, choose the one with the smaller AjA_j.

Input Format

The first line contains an integer nn, the length of the sequence.

The second line contains nn integers A1AnA_1 \sim A_n, representing the values of the sequence, separated by spaces.

Output Format

Output a total of n1n - 1 lines, each line containing two integers separated by a space.

For each ii from 2n2 \sim n, output the corresponding values of min1j<iAiAj\min_{1 \le j < i} |A_i - A_j| and PiP_i.

3
1 5 3
4 1
2 1

Hint

For 30%30\% of the testdata, n100n \le 100.

For 70%70\% of the testdata, n104n \le 10^4.

For 100%100\% of the testdata, n105,Ai109n \le 10^5, |A_i| \le 10^9.

Translated by ChatGPT 5