#P8103. 「LCOI2022」 Cow Merger
「LCOI2022」 Cow Merger
Description
Farmer John’s farm originally has barns. The -th barn contains cows.
We define one operation of merging two barns () as follows: take cows out of barn and move them into barn . If after the merge ends , then we can consider to have been merged, and the following operations will no longer be related to .
Because time is running out, he decides to give you at most second.
Input Format
The first line contains an integer , which denotes the number of test cases.
For the -th test case:
Line contains an integer .
Line contains integers, where the -th integer is .
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 , which denotes the number of operations.
Then output lines, each containing two numbers and (note that during an operation, it should satisfy ).
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 of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号