It is winter now, and Max decided it's about time he watered the garden.
The garden can be represented as n consecutive garden beds, numbered from 1 to n. k beds contain water taps (i-th tap is located in the bed xi), which, if turned on, start delivering water to neighbouring beds. If the tap on the bed xi is turned on, then after one second has passed, the bed xi will be watered; after two seconds have passed, the beds from the segment [xi - 1, xi + 1] will be watered (if they exist); after j seconds have passed (j is an integer number), the beds from the segment [xi - (j - 1), xi + (j - 1)] will be watered (if they exist). Nothing changes during the seconds, so, for example, we can't say that the segment [xi - 2.5, xi + 2.5] will be watered after 2.5 seconds have passed; only the segment [xi - 2, xi + 2] will be watered at that moment.
The garden from test 1. White colour denotes a garden bed without a tap, red colour — a garden bed with a tap. The garden from test 1 after 2 seconds have passed after turning on the tap. White colour denotes an unwatered garden bed, blue colour — a watered bed.
Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered. Help him to find the answer!
Input
The first line contains one integer t — the number of test cases to solve (1 ≤ t ≤ 200).
Then t test cases follow. The first line of each test case contains two integers n and k (1 ≤ n ≤ 200, 1 ≤ k ≤ n) — the number of garden beds and water taps, respectively.
Next line contains k integers xi (1 ≤ xi ≤ n) — the location of i-th water tap. It is guaranteed that for each condition xi - 1 < xi holds.
It is guaranteed that the sum of n over all test cases doesn't exceed 200.
Note that in hacks you have to set t = 1.
Output
For each test case print one integer — the minimum number of seconds that have to pass after Max turns on some of the water taps, until the whole garden is watered.
Example
Input
3
5 1
3
3 3
1 2 3
4 1
1
Output
3
1
4
Note
The first example consists of 3 tests:
There are 5 garden beds, and a water tap in the bed 3. If we turn it on, then after 1 second passes, only bed 3 will be watered; after 2 seconds pass, beds [1, 3] will be watered, and after 3 seconds pass, everything will be watered.
There are 3 garden beds, and there is a water tap in each one. If we turn all of them on, then everything will be watered after 1 second passes.
There are 4 garden beds, and only one tap in the bed 1. It will take 4 seconds to water, for example, bed 4.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
We need to understand the problem: given n consecutive positions 1..n, and k taps at distinct positions (strictly increasing). Max will turn on some of the taps (possibly all, but maybe not all? Wait: "the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered." He can choose which taps to turn on? The phrasing: "Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered." It might be ambiguous: He can choose to turn on some taps (not necessarily all) to minimize the time needed to water the whole garden. But is turning on extra taps beneficial? Typically yes, because more sources can water faster. However, there's no cost to turning on all taps; turning on extra taps can only help (or be neutral) because they water additional areas. Since he can turn on any subset, the optimal is to turn on all taps. But wait, there might be nuance: The taps are located in specific beds. If you turn on a tap, it starts watering outward. There's no disadvantage: water from different taps can overlap; it's fine. So the best is to turn on all taps. However, the problem statement: "Max wants to turn on all the water taps at the same moment" suggests that he will turn on all of them. But then "turns on some taps" seems contradictory. Actually reading: "Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered." This might be a translation issue. Possibly it means: He can turn on some taps (i.e., he may not need to turn on all; but if he turns on all it might not be optimal? Wait, could turning on some taps be worse? No, turning on more taps can only water more, so it's always at least as good. So the minimal time is achieved by turning on all taps. But maybe there is some limitation: water from taps might interfere? No. So likely it's "some" meaning "the taps he turns on" which is actually all taps. But the phrase "some" might be generic. Let's check the sample:
Test 1: n=5, one tap at 3, answer 3. That's consistent: turning on the only tap, time = max distance to ends: to left end distance = 3-1=2, to right end =5-3=2, so time = max(2,2)+1? Actually after 2 seconds, segment [xi-1, xi+1] = [2,4] watered, after 3 seconds, [1,5] watered. So time = (distance to farthest bed) + 1? For a single tap at pos p, the time needed to cover a bed at distance d (in terms of number of beds away) is d+1? Let's see: At time t, the watered segment is [p-(t-1), p+(t-1)]. To cover a bed at distance d from p, we need t-1 >= d => t >= d+1. So time = distance + 1. So for both ends, max distance = max(p-1, n-p). So answer = max(p-1, n-p) + 1. For p=3, max(2,2)+1=3. Yes.
Test 2: n=3, taps at 1,2,3. If we turn on all, after 1 second each tap waters its own bed, so the entire garden is watered? At time 1, tap at 1 waters [1], tap at 2 waters [2], tap at 3 waters [3], so yes all are covered. So answer 1. That's consistent.
Test 3: n=4, tap at 1. Answer 4. max distance = 4-1=3 => 3+1=4. Yes.
So for a single tap, answer = max(x1-1, n-x1) + 1.
But for multiple taps, we need to find the minimal time such that the union of intervals from each tap (after time t) covers [1,n]. Each tap i at xi, at time t, waters [xi-(t-1), xi+(t-1)] intersect [1,n] (we can consider that they water only existing beds). We want smallest integer t such that union covers [1,n].
We can think of each tap covering an interval of length 2*(t-1)+1 = 2t-1, centered at xi. We want to cover the whole line segment [1,n]. This is a classic covering problem: given intervals (centered at given points) with same length L = 2t-1 (odd length), we want to know if they cover [1,n]. The minimal t is the smallest integer such that with that length, the union covers all.
Equivalently, t is the minimal integer such that the maximum gap between consecutive taps (considering boundaries) is covered. Because the taps spread outward. Let's reason.
Consider sorted taps x1 < x2 < ... < xk. At time t, each tap covers from xi - (t-1) to xi + (t-1). The leftmost covered point is max(1, x1 - (t-1)). The rightmost covered point is min(n, xk + (t-1)). The whole [1,n] is covered if:
The leftmost coverage reaches 1: x1 - (t-1) <= 1, i.e., t >= x1.
The rightmost coverage reaches n: xk + (t-1) >= n, i.e., t >= n - xk + 1.
For each adjacent pair of taps xi and xi+1, their intervals must overlap or touch: i.e., xi + (t-1) >= xi+1 - (t-1) - 1? Actually to cover all integer points, we need that the union covers the whole segment continuously. That means there is no gap between the intervals. The interval from xi extends to right until xi + (t-1). The interval from xi+1 extends left until xi+1 - (t-1). For these intervals to cover the points between them, we need xi + (t-1) >= xi+1 - (t-1) - 1? Let's think: If intervals are [L_i,R_i] and [L_{i+1},R_{i+1}], we need that there is no uncovered integer point between them. That means R_i >= L_{i+1} - 1? Actually if R_i >= L_{i+1} - 1, then any integer point from L_i to R_i is covered, and L_{i+1} is the start of next interval. The uncovered points would be those > R_i and < L_{i+1}. If R_i >= L_{i+1} - 1, then the next integer after R_i is R_i+1. If L_{i+1} <= R_i+1, then R_i+1 is covered if L_{i+1} <= R_i+1? Let's do example: intervals [1,3] and [5,7]; uncovered integer = 4. Here R_i=3, L_{i+1}=5; R_i+1=4, L_{i+1}-1=4. Condition to cover gap: we need R_i >= L_{i+1} - 1? 3 >= 4? false. Alternatively, we need R_i + 1 >= L_{i+1}? 4 >= 5? false. So the condition is that intervals must overlap or at least touch: i.e., xi + (t-1) >= xi+1 - (t-1) - 1? Actually if they just touch at a point, say R_i = L_{i+1}, then the integer L_{i+1} is covered by the second interval, integer R_i is covered by first, but what about R_i? That's fine. But is there any integer between R_i and L_{i+1}? If R_i = L_{i+1}, there is no integer between them. So that's okay. So condition: xi + (t-1) >= xi+1 - (t-1). Because if the right endpoint of first interval equals the left endpoint of second, then they meet at a point. That point is integer? Yes, because both endpoints are integers. So the condition is: xi + (t-1) >= xi+1 - (t-1). Simplify: 2(t-1) >= xi+1 - xi, i.e., t-1 >= (xi+1 - xi)/2. Since t integer, we need t >= ceil((xi+1 - xi)/2) + 1? Actually let's derive properly: We require that intervals cover all points, i.e., no gap: R_i >= L_{i+1} - 1? Wait, we need that every integer point from 1 to n is covered. For an integer point p between xi and xi+1, if p <= xi + (t-1) then it's covered by left interval; if p >= xi+1 - (t-1) then it's covered by right interval. There is a gap if xi + (t-1) < xi+1 - (t-1) - 1? Actually consider p = xi + (t-1) + 1. This is the first integer not covered by left interval. It will be covered by right interval if xi+1 - (t-1) <= p <= xi+1 + (t-1). So we need xi+1 - (t-1) <= xi + (t-1) + 1. Rearranged: xi+1 - xi <= 2(t-1) + 1. That is a condition: the distance between taps must be <= 2t-1? Let's check: 2(t-1)+1 = 2t-1. So if the gap between taps (xi+1 - xi) <= 2t-1, then the coverage from the two taps will meet or overlap? Actually let's test: t=2 => coverage radius 1 (cover 1 to each side). Interval length = 3. For taps at positions 1 and 4, distance =3. Does coverage cover all? Tap1 covers [1-1,1+1] = [0,2] but only [1,2] relevant. Tap2 covers [3,5] but only [3,4] if n=5? Actually if n=5, tap2 at 4 covers [3,5] so covered points are 1,2,3,4,5? Let's see: tap1 covers 1,2; tap2 covers 3,4,5. So all covered. Gap: distance between taps is 3, and 2t-1 = 3, condition holds equality. So covered. For taps at 1 and 5, distance=4, 2t-1=3, not covered; there is a gap at 4? Actually tap1 covers [1,2]; tap5 covers [4,6] intersect [1,5] => [4,5]; point 3 is uncovered. So yes gap. So the condition is: xi+1 - xi <= 2t-1.
Also, edges: we need coverage of first tap to reach 1: x1 - (t-1) <= 1 => t >= x1. That is equivalent to x1 - 1 <= t-1 => distance from left end to first tap must be <= t-1? Actually x1-1 is the distance from bed 1 to x1. For coverage, we need t-1 >= x1-1 => t >= x1. So condition: x1 - 1 <= t-1 -> t >= x1. Similarly for right: n - xk <= t-1 => t >= n - xk + 1.
Thus the minimal t is the minimum integer such that:
t >= x1
t >= n - xk + 1
For each i, t >= ceil((xi+1 - xi + 1)/2)? Let's derive from condition xi+1 - xi <= 2t-1 => 2t-1 >= d, where d = xi+1 - xi. So t >= (d+1)/2. Since t integer, t >= ceil((d+1)/2). But careful: d = xi+1 - xi. Then (d+1)/2 could be not integer. For d=3, (3+1)/2=2 => t>=2; we saw t=2 works? For taps at 1 and 4, distance 3, t=2, condition gives t>=2, so t=2 works. For d=2, (2+1)/2=1.5 => ceil=2 => t>=2? But check: taps at 1 and 3, distance 2, t=2 gives coverage: tap1 covers [1,2]; tap2 covers [2,3]; all covered. So t=2 works. Could t=1 work? t=1: each covers only its own bed: so beds 1 and 3 covered, bed 2 uncovered. So need t>=2. So condition t >= ceil((d+1)/2) is correct. Alternatively, t >= floor((d+2)/2)? Let's compute ceil((d+1)/2). For d=2, ceil(1.5)=2. Good.
Now also note that we might consider intervals between taps possibly overlapping with edges? The edge conditions are similar: For leftmost, we need to cover from 1 to x1. The distance from 1 to x1 is (x1 - 1). To cover that with the leftmost tap's expansion, we need t-1 >= x1-1 => t >= x1. This is like considering a "virtual" tap at position 0? Actually if we treat the left boundary as a tap that must be covered, we could think of condition: the gap from 0 to x1? But we have a condition: t >= x1. That's equivalent to ceil((x1 - 0 + 1)/2)? Not exactly, because the distance from 0 to x1 is x1, but we need t >= ceil((x1+1)/2)? Let's test: n=5, x1=3 => x1=3, we got t >=3 from edge? Actually t must be >= x1=3? Wait from earlier we said t >= x1? For x1=3, t>=3. But our earlier single tap case gave answer 3, indeed t=3. However, if we apply condition t >= ceil((x1+1)/2) = ceil(4/2)=2, that would be too low. So edge condition is different because there's only one side to cover. The expansion from a single point to cover a distance d requires t = d+1 (since coverage grows linearly). For two taps covering a gap of distance d between them, the required t is ceil((d+1)/2). For one side (from tap to edge), it's d+1. Because there's only one source expanding toward the edge.
Thus overall minimal t = max( x1, n - xk + 1, max over i of ceil((xi+1 - xi + 1)/2? Wait careful: For gap between taps, we derived condition: xi+1 - xi <= 2t-1 => t >= ceil((xi+1 - xi + 1)/2). Because (d+1)/2. Let's denote for each gap d_i = xi+1 - xi. Then required t_i = ceil((d_i + 1)/2). For left edge, required t_left = x1 (since t >= x1). For right edge, required t_right = n - xk + 1.
But is that always correct? Check with sample 2: n=3, taps [1,2,3]. Compute: x1=1 => t_left=1. t_right = 3-3+1=1. Gaps: between 1 and 2: d=1 => ceil((1+1)/2)=ceil(1)=1? Actually (1+1)/2=1, ceil(1)=1. So t_gap=1. So max =1. Correct.
Check with sample 1: x1=3 => t_left=3; t_right=5-3+1=3; gaps: none (only one tap). max=3.
Check with sample 3: x1=1 => t_left=1; t_right=4-1+1=4; max=4.
Now test additional cases: Suppose n=5, taps at [2,4]. Compute: t_left = 2; t_right = 5-4+1=2; gaps: d=2 => ceil((2+1)/2)=ceil(1.5)=2. max=2. Let's simulate: t=2 => tap2 covers [1,3]? Actually tap at 2 covers [2-1,2+1]=[1,3]; tap at 4 covers [3,5]; union covers [1,5]? yes (1,2,3,4,5). So answer 2. Could t=1? t=1 => covers only [2] and [4]; not all. So answer 2. Good.
Suppose n=5, taps at [1,5]. Then t_left=1; t_right=1; gap d=4 => ceil((4+1)/2)=ceil(2.5)=3. So answer=3. Check: t=3 => tap1 covers [1-2,1+2]=[-1,3] -> [1,3]; tap5 covers [3,7] -> [3,5]; union covers [1,5]; t=2? t=2 => tap1 covers [1,2]; tap5 covers [4,5]; 3 uncovered. So need t=3. Good.
Suppose n=6, taps at [2,5]. t_left=2; t_right=6-5+1=2; gap d=3 => ceil((3+1)/2)=2; max=2. t=2 => tap2 covers [1,3]; tap5 covers [4,6]; union covers [1,6]? Actually tap5 at t=2 covers [4,6] (since 5-1=4, 5+1=6) -> yes, union covers 1-6. So answer 2.
Suppose n=6, taps at [1,6]. t_left=1; t_right=1; gap d=5 => ceil(6/2)=3; answer=3. t=2 would cover [1,2] and [5,6] missing 3,4; t=3 covers [1,3] and [4,6] union all? Actually tap1 at t=3 covers [-1,3] -> [1,3]; tap6 covers [4,8] -> [4,6]; union covers all. So 3.
Thus formula seems correct.
But wait: is it always optimal to turn on all taps? Could turning off some taps lead to a smaller time? Suppose we have taps that are close together; turning on all is fine. But could there be a scenario where some taps cause "overlap" but not help? It never hurts; adding more sources can only reduce the maximum distance needed to cover gaps? Actually adding a tap can only help, because it reduces the effective gaps between active taps. However, turning on all taps always yields the minimal time because any subset would have larger gaps (since you remove some taps) or larger edge distances. So turning on all taps is optimal.
But careful: For the gap, we derived t >= ceil((d+1)/2). That's correct. However, we need to confirm that t must be integer and we consider the discrete time steps. The watering process is defined such that at integer seconds j, the watered segment is [xi - (j-1), xi + (j-1)]. So the coverage expands by 1 in each direction each second (starting at j=1 covering only the tap). So the formula holds.
Edge cases: if k=1, then answer = max(x1, n - x1 + 1) because there are no gaps. Our formula includes max over gaps which is empty, so overall max = max(t_left, t_right). And indeed t_left = x1, t_right = n - x1 + 1. That matches.
Now we need to implement for t test cases, sum of n <= 200, so trivial.
But wait: The problem statement says: "Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered." It could be interpreted as: He can choose which taps to turn on (some of them) to minimize the time. But as argued, turning on all is always optimal. However, there might be nuance: The taps, when turned on, water the garden as described. If you turn on a tap, it will water its own bed after 1 second. But if you don't turn on a tap, that bed might still be watered by neighboring taps. So turning on extra taps can only help because it provides another source. Unless turning on a tap somehow "overwrites" something? No. So indeed optimal to turn on all.
But I recall a Codeforces problem (maybe "Watering the Garden" or something) where you have to choose which taps to turn on to minimize time, and sometimes you might not need to turn on all because they are redundant? But even if redundant, turning them on doesn't increase time; it's still same or less. So turning on all is never worse. However, the problem might be about "some taps" meaning you can turn on any subset, and you want the minimal time possible, i.e., you can choose to turn on only a subset, maybe you cannot turn on all because of some constraint? The description says: "Max wants to turn on all the water taps at the same moment", so he intends to turn on all. But then why ask "some taps"? Possibly it's a translation: "some taps" meaning "the taps" as in the ones he turns on (which are all). But the phrase "some of the water taps" suggests he might not turn on all? However, the note says "If we turn it on" for first test, there is only one. For second: "If we turn all of them on". So they consider turning on all. So answer using all taps is correct.
Thus solution: For each test, read n,k, array x (sorted). Compute max_edge = max(x[0], n - x[k-1] + 1). Then compute max_gap = 0; For i=0 to k-2: d = x[i+1] - x[i]; needed = (d + 1) // 2 if (d+1) is even? Actually ceil((d+1)/2) = (d+2)//2? Let's derive: We want ceil((d+1)/2). Since (d+1) might be even or odd. For integer A, ceil(A/2) = (A+1)//2. So for A = d+1, ceil((d+1)/2) = (d+2)//2. Let's test: d=1 -> A=2, ceil(2/2)=1, (d+2)//2 = 3//2=1 (since 3/2 floor=1). Actually (1+2)//2 = 3//2=1. So correct. d=2 -> A=3, ceil(3/2)=2, (2+2)//2=4//2=2. d=3 -> A=4, ceil=2, (3+2)//2=5//2=2. d=4 -> A=5, ceil=3, (4+2)//2=6//2=3. So yes needed = (d+2)//2.
Alternatively needed = (d // 2) + 1? For d even, say d=2: d//2=1, +1=2. For d=4: d//2=2, +1=3. For d odd, d=3: d//2=1, +1=2; correct. For d=1: d//2=0, +1=1. So also works: needed = (d // 2) + 1. But careful: For d=0? Taps are distinct so d>=1. So either is fine.
Example 2: n=3, x=[1,2,3] -> max_edge = max(1,3-3+1=1)=1; gaps: between 1&2 d=1 needed= (1+2)//2=1; between2&3 d=1 needed=1; max_gap=1; answer=1.
Example 3: n=4, x=[1] -> max_edge = max(1,4-1+1=4)=4; answer=4.
Edge: n=1, k=1, x=[1]. Then max_edge = max(1,1-1+1=1)=1; answer=1. Should be correct: at t=1, bed 1 watered.
n=200, etc.
Thus solution straightforward.
Now we must produce output for each test case.
But wait: The problem statement says "Max wants to turn on all the water taps at the same moment, and now he wonders, what is the minimum number of seconds that have to pass after he turns on some taps until the whole garden is watered." Could it be that he can only turn on some taps (maybe not all) but wants to minimize the number of taps turned on? No, the question asks for minimum number of seconds, not number of taps. So it's about time.
Thus answer as above.
Double-check with some more complex cases:
Case: n=10, taps at [3,7]. Compute: left edge t_left=3; right edge t_right=10-7+1=4; gap d=4 => needed=(4+2)//2=3; max= max(3,4,3)=4. So answer=4. Let's simulate: t=4 -> tap3 covers [3-3,3+3]=[0,6] -> [1,6]; tap7 covers [7-3,7+3]=[4,10]; union = [1,10]? Actually [1,6] U [4,10] = [1,10]. t=3 -> tap3 covers [1,5]; tap7 covers [5,9]; union = [1,9]? 10 uncovered? Wait tap7 at t=3 covers [7-2,7+2]=[5,9] (since t=3 => (t-1)=2). So covers 5-9. So union covers 1-5 from first, 5-9 from second, but bed 10 is not covered. So t=3 fails. So answer 4 correct.
Case: n=10, taps at [2,5,9]. Compute: left edge=2; right edge=10-9+1=2; gaps: d1=3 => needed=(3+2)//2=2 (since 5//2=2? Actually (3+2)//2=5//2=2), d2=4 => needed=3; max_gap=3; overall max= max(2,2,3)=3. So answer=3. Simulate t=3: tap2 covers [2-2,2+2]=[0,4] -> [1,4]; tap5 covers [5-2,5+2]=[3,7]; tap9 covers [9-2,9+2]=[7,11] -> [7,10]; union: [1,4] U [3,7] U [7,10] = [1,10]. t=2: tap2 covers [1,3]; tap5 covers [4,6]; tap9 covers [8,10]; bed 7 uncovered? Actually tap5 covers [4,6] (since t=2 => radius 1), tap9 covers [8,10], there is gap at 7. So t=2 fails. So answer 3 correct.
All good.
Now the input constraints: t up to 200, sum n <= 200. So O(n) per test is fine.
Implementation:
for each test:
read n,k
read k integers into list
sort list (though they said condition xi-1 < xi holds, meaning they are strictly increasing? Actually it says: "It is guaranteed that for each condition xi - 1 < xi holds." That might be a misprint; probably means "xi-1 < xi" meaning that the positions are given in increasing order? Actually they wrote: "It is guaranteed that for each condition xi - 1 < xi holds." Possibly meaning that the sequence is strictly increasing: xi-1 < xi for all i>1. Yes, it's typical: they guarantee the input is sorted and distinct. But they might not guarantee sorted order? Usually they say "It is guaranteed that xi < xi+1". However the phrasing "xi - 1 < xi" might be a formatting error due to latex? They might have meant "xi-1 < xi" i.e., the previous element is less than the current. So we can assume sorted. But just to be safe, we can sort the list.
Thus code:
def solve():
import sys
data = sys.stdin.read().strip().split()
it = iter(data)
t = int(next(it))
out = []
for _ in range(t):
n = int(next(it)); k = int(next(it))
x = [int(next(it)) for __ in range(k)]
x.sort()
left = x[0]
right = n - x[-1] + 1
max_gap = 0
for i in range(k-1):
d = x[i+1] - x[i]
needed = (d + 2) // 2 # ceil((d+1)/2)
if needed > max_gap:
max_gap = needed
ans = max(left, right, max_gap)
out.append(str(ans))
sys.stdout.write("\n".join(out))
Check: For test case where taps include 1 and n, left=1, right=1. Gaps may require >1. So fine.
Now confirm with given examples.
But wait: The problem statement includes images but not relevant.
Thus final answer.
But let's also think about alternative interpretations: Could the answer be simply the maximum of distances from each segment to nearest tap? Actually we derived correctly.
One more check: For n=100, taps at [1,100], answer = max(1,1, ceil((99+1)/2)=50) => 50. At t=50, tap1 covers [1-49,1+49]=[-48,50] -> [1,50]; tap100 covers [100-49,100+49]=[51,149]->[51,100]; union covers all. Yes.
If we had three taps, the worst gap might be the largest half-distance.
Now we need to be careful: The problem might be originally from Codeforces Round #... and the solution is indeed as above.
Thus we produce the solution.
Now I will output the final answer with explanation. We need to find the minimal integer time (t) such that after turning on all taps (since more taps never hurt) the whole segment ([1, n]) is watered.
Each tap at position (x_i) waters at time (t) the interval ([x_i-(t-1), x_i+(t-1)]) (intersected with ([1,n])).
For coverage we need:
The leftmost tap reaches bed 1: (x_1 - (t-1) \le 1) → (t \ge x_1).
The rightmost tap reaches bed (n): (x_k + (t-1) \ge n) → (t \ge n - x_k + 1).
For every adjacent pair (x_i, x_{i+1}), their intervals must meet or overlap, i.e.
(x_i + (t-1) \ge x_{i+1} - (t-1)). This gives (2(t-1) \ge x_{i+1} - x_i) → (t \ge \left\lceil\frac{x_{i+1} - x_i + 1}{2}\right\rceil).
Thus the answer is
[
t = \max\left(; x_1,; n - x_k + 1,; \max_{i=1}^{k-1} \left\lceil\frac{x_{i+1} - x_i + 1}{2}\right\rceil ;\right).
]
Implementation details:
The taps are given in increasing order, but sorting once is safe.
For a gap (d = x_{i+1} - x_i), (\left\lceil\frac{d+1}{2}\right\rceil = \frac{d+2}{2}) integer division (floor) in Python: (d + 2) // 2.
Since total (n) over all test cases is at most 200, the solution runs easily.
python
import sys
def solve() -> None:
data = sys.stdin.read().strip().split()
if not data:
return
it = iter(data)
t = int(next(it))
out = []
for _ in range(t):
n = int(next(it))
k = int(next(it))
x = [int(next(it)) for _ in range(k)]
x.sort()
left = x[0] # t must be at least x[0]
right = n - x[-1] + 1 # t must be at least n - x_k + 1
max_gap = 0
for i in range(k - 1):
d = x[i+1] - x[i]
needed = (d + 2) // 2 # ceil((d+1)/2)
if needed > max_gap:
max_gap = needed
ans = max(left, right, max_gap)
out.append(str(ans))
sys.stdout.write("\n".join(out))
if __name__ == "__main__":
solve()