#P2902. Pearl Pairing
Pearl Pairing
Pearl Pairing
At Bessie's recent birthday party, she received $\;N\;(2 \le N \le 10^5,\, N \equiv 0 \pmod{2})$ pearls painted in one of $C$ different colors ($1 \le C \le N$). For the $i$-th color, there are $C_i$ pearls such that \(\sum_{i=1}^{C}C_i = N\). Since $N$ is even, Bessie decided to pair the pearls in such a way that each pair consists of two pearls of different colors.
It is guaranteed that a valid pairing exists. If there are multiple solutions, any one will be accepted.
inputFormat
The first line contains two integers, N
and C
, representing the total number of pearls and the number of different colors, respectively.
The second line contains C
integers: C1, C2, ..., CC
, where Ci
is the number of pearls of the i-th color. It is guaranteed that \(\sum_{i=1}^{C} C_i = N\) and that N
is even.
outputFormat
Output N/2
lines, each containing two integers. Each line represents a pair of pearl indices (the pearls are numbered from 1 to N in the order they appear: first all pearls of color 1, then color 2, etc.) such that the two pearls in the pair have different colors.
sample
4 2
2 2
1 3
2 4
</p>