2026B.md (1685B)
1 Source: https://codeforces.com/problemset/problem/2026/B 2 3 B. Black Cells 4 5 time limit per test 6 7 2 seconds 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 are given a strip divided into cells, numbered from left to right from $0$ to $10^{18}$. Initially, all cells are white. 22 23 You can perform the following operation: choose two white cells $i$ and $j$, such that $i \ne j$ and $|i - j| \le k$, and paint them black. 24 25 A list $a$ is given. All cells from this list must be painted black. Additionally, at most one cell that is not in this list can also be painted black. Your task is to determine the minimum value of $k$ for which this is possible. 26 27 Input 28 29 The first line contains a single integer $t$ ($1 \le t \le 500$) — the number of test cases. 30 31 The first line of each test case contains a single integer $n$ ($1 \le n \le 2000$). 32 33 The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \lt a_i \lt 10^{18}$; $a_i \lt a_{i + 1}$). 34 35 Additional constraint on the input: the sum of $n$ across all test cases does not exceed $2000$. 36 37 Output 38 39 For each test case, print a single integer — the minimum value of $k$ for which it is possible to paint all the given cells black. 40 41 Example 42 43 Input 44 45 ``` 46 4 47 48 2 49 50 1 2 51 52 1 53 54 7 55 56 3 57 58 2 4 9 59 60 5 61 62 1 5 8 10 13 63 ``` 64 65 Output 66 67 ``` 68 1 69 1 70 2 71 3 72 ``` 73 74 Note 75 76 In the first example, with $k=1$, it is possible to paint the cells $(1, 2)$. 77 78 In the second example, with $k=1$, it is possible to paint the cells $(7, 8)$. 79 80 In the third example, with $k=2$, it is possible to paint the cells $(2, 4)$ and $(8, 9)$. 81 82 In the fourth example, with $k=3$, it is possible to paint the cells $(0, 1)$, $(5, 8)$ and $(10, 13)$.