#P8103. 「LCOI2022」 Cow Merger

「LCOI2022」 Cow Merger

Description

Farmer John’s farm originally has nn barns. The ii-th barn contains aia_i cows.

We define one operation of merging two barns i,ji, j (aiaja_i \ge a_j) as follows: take aja_j cows out of barn ii and move them into barn jj. If after the merge ends ai=0a_i = 0, then we can consider aia_i to have been merged, and the following operations will no longer be related to aia_i.

Because time is running out, he decides to give you at most 11 second.

Input Format

The first line contains an integer TT, which denotes the number of test cases.

For the tt-th test case:

Line 2t2t contains an integer nn.

Line 2t+12t + 1 contains nn integers, where the ii-th integer is aia_i.

Output Format

For each test case:

If you find that it is impossible to reach the goal, output NO; otherwise output YES.

Then output one line containing an integer mm, which denotes the number of operations.

Then output mm lines, each containing two numbers ii and jj (note that during an operation, it should satisfy aiaja_i \ge a_j).

If there are multiple solutions, you may output any one of them.

3
4
1 2 3 2
5
3 9 6 18 12
5
2 3 5 7 11
YES
4
3 1
1 2
3 4
2 4
YES
6
2 1
1 2
4 3
2 3
4 5
3 5
NO

Hint

[Constraints and Notes]

For 100%100\% of the testdata, 1T51 \leq T \leq 5, 1n1051 \leq n \leq 10^5, 0ai1090 \leq a_i \leq 10^9.

Translated by ChatGPT 5