P8103 "LCOI2022" Cow Merger
Background
After Bessie arrived at her new home, Farmer John suddenly realized that his farm was not big enough anymore.
So, Farmer John needs to merge all the cows into one barn.
Description
Farmer John’s farm originally has $n$ barns. The $i$-th barn contains $a_i$ cows.
We define one operation of merging two barns $i, j$ ($a_i \ge a_j$) as follows: take $a_j$ cows out of barn $i$ and move them into barn $j$. If after the merge ends $a_i = 0$, then we can consider $a_i$ to have been merged, and the following operations will no longer be related to $a_i$.
Because time is running out, he decides to give you at most $1$ second.
Input Format
The first line contains an integer $T$, which denotes the number of test cases.
For the $t$-th test case:
Line $2t$ contains an integer $n$.
Line $2t + 1$ contains $n$ integers, where the $i$-th integer is $a_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 $m$, which denotes the number of operations.
Then output $m$ lines, each containing two numbers $i$ and $j$ (note that during an operation, it should satisfy $a_i \ge a_j$).
**If there are multiple solutions, you may output any one of them.**
Explanation/Hint
[Constraints and Notes]
For $100\%$ of the testdata, $1 \leq T \leq 5$, $1 \leq n \leq 10^5$, $0 \leq a_i \leq 10^9$.
Translated by ChatGPT 5