1607C.md (3140B)
1 Source: https://codeforces.com/problemset/problem/1607/C 2 3 C. Minimum Extraction 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 Yelisey has an array $a$ of $n$ integers. 22 23 If $a$ has length strictly greater than $1$, then Yelisei can apply an operation called minimum extraction to it: 24 25 1. First, Yelisei finds the minimal number $m$ in the array. If there are several identical minima, Yelisey can choose any of them. 26 2. Then the selected minimal element is removed from the array. After that, $m$ is subtracted from each remaining element. 27 28 Thus, after each operation, the length of the array is reduced by $1$. 29 30 For example, if $a = [1, 6, -4, -2, -4]$, then the minimum element in it is $a_3 = -4$, which means that after this operation the array will be equal to $a=[1 {- (-4)}, 6 {- (-4)}, -2 {- (-4)}, -4 {- (-4)}] = [5, 10, 2, 0]$. 31 32 Since Yelisey likes big numbers, he wants the numbers in the array $a$ to be as big as possible. 33 34 Formally speaking, he wants to make the minimum of the numbers in array $a$ to be maximal possible (i.e. he want to maximize a minimum). To do this, Yelisey can apply the minimum extraction operation to the array as many times as he wants (possibly, zero). Note that the operation cannot be applied to an array of length $1$. 35 36 Help him find what maximal value can the minimal element of the array have after applying several (possibly, zero) minimum extraction operations to the array. 37 38 Input 39 40 The first line contains an integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. 41 42 The next $2t$ lines contain descriptions of the test cases. 43 44 In the description of each test case, the first line contains an integer $n$ ($1 \leq n \leq 2 \cdot 10^5$) — the original length of the array $a$. The second line of the description lists $n$ space-separated integers $a_i$ ($-10^9 \leq a_i \leq 10^9$) — elements of the array $a$. 45 46 It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$. 47 48 Output 49 50 Print $t$ lines, each of them containing the answer to the corresponding test case. The answer to the test case is a single integer — the maximal possible minimum in $a$, which can be obtained by several applications of the described operation to it. 51 52 Example 53 54 Input 55 56 ``` 57 8 58 1 59 10 60 2 61 0 0 62 3 63 -1 2 0 64 4 65 2 10 1 7 66 2 67 2 3 68 5 69 3 2 -4 -2 0 70 2 71 -1 1 72 1 73 -2 74 ``` 75 76 Output 77 78 ``` 79 10 80 0 81 2 82 5 83 2 84 2 85 2 86 -2 87 ``` 88 89 Note 90 91 In the first example test case, the original length of the array $n = 1$. Therefore minimum extraction cannot be applied to it. Thus, the array remains unchanged and the answer is $a_1 = 10$. 92 93 In the second set of input data, the array will always consist only of zeros. 94 95 In the third set, the array will be changing as follows: $[\color{blue}{-1}, 2, 0] \to [3, \color{blue}{1}] \to [\color{blue}{2}]$. The minimum elements are highlighted with $\color{blue}{\text{blue}}$. The maximal one is $2$. 96 97 In the fourth set, the array will be modified as $[2, 10, \color{blue}{1}, 7] \to [\color{blue}{1}, 9, 6] \to [8, \color{blue}{5}] \to [\color{blue}{3}]$. Similarly, the maximum of the minimum elements is $5$.