1474C.md (2230B)
1 Source: https://codeforces.com/problemset/problem/1474/C 2 3 C. Array Destruction 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 You found a useless array $a$ of $2n$ positive integers. You have realized that you actually don't need this array, so you decided to throw out all elements of $a$. 22 23 It could have been an easy task, but it turned out that you should follow some rules: 24 25 1. In the beginning, you select any positive integer $x$. 26 2. Then you do the following operation $n$ times: 27 * select two elements of array with sum equals $x$; 28 * remove them from $a$ and replace $x$ with maximum of that two numbers. 29 30 For example, if initially $a = [3, 5, 1, 2]$, you can select $x = 6$. Then you can select the second and the third elements of $a$ with sum $5 + 1 = 6$ and throw them out. After this operation, $x$ equals $5$ and there are two elements in array: $3$ and $2$. You can throw them out on the next operation. 31 32 Note, that you choose $x$ before the start and can't change it as you want between the operations. 33 34 Determine how should you behave to throw out all elements of $a$. 35 36 Input 37 38 The first line contains a single integer $t$ ($1 \leq t \leq 1000$) — the number of test cases. 39 40 The first line of each test case contains the single integer $n$ ($1 \leq n \leq 1000$). 41 42 The second line of each test case contains $2n$ integers $a_1, a_2, \dots, a_{2n}$ ($1 \leq a_i \leq 10^6$) — the initial array $a$. 43 44 It is guaranteed that the total sum of $n$ over all test cases doesn't exceed $1000$. 45 46 Output 47 48 For each test case in the first line print YES if it is possible to throw out all elements of the array and NO otherwise. 49 50 If it is possible to throw out all elements, print the initial value of $x$ you've chosen. Print description of $n$ operations next. For each operation, print the pair of integers you remove. 51 52 Example 53 54 Input 55 56 ``` 57 4 58 2 59 3 5 1 2 60 3 61 1 1 8 8 64 64 62 2 63 1 1 2 4 64 5 65 1 2 3 4 5 6 7 14 3 11 66 ``` 67 68 Output 69 70 ``` 71 YES 72 6 73 1 5 74 2 3 75 NO 76 NO 77 YES 78 21 79 14 7 80 3 11 81 5 6 82 2 4 83 3 1 84 ``` 85 86 Note 87 88 The first test case was described in the statement. 89 90 In the second and third test cases, we can show that it is impossible to throw out all elements of array $a$.