P17651 [IO 2025 #1] Shelter
Description
A taut silk thread stretches across Pharloom, and $n$ little inhabitants live on this thread. The $i$-th inhabitant is at coordinate $x_i$. Some cocoons need to be placed on the thread as their shelters.
Once the cocoons are placed, every inhabitant goes to the shelter closest to them. That is, if the cocoons are at coordinates $a_1,\ldots,a_k$, then for each $x_i$, a $j_i$ minimizing $|x_i-a_{j_i}|$ is chosen. The **danger level** of this set of cocoons is defined as $D=\max_{i=1}^n|x_i-a_{j_i}|$, i.e., the maximum distance from an inhabitant to their nearest shelter.
Hornet receives $q$ independent requests. Each request specifies:
- an integer $k$, the total number of cocoon shelters that must be placed on the thread in the end;
- an integer $r$ and a set of coordinates $a_1,\ldots,a_r$, the positions of $r$ shelters that are already fixed.
She needs to add $k-r$ more shelters at arbitrary positions on the thread so that the final danger level is as small as possible. The coordinates of the new shelters do not have to be integers.
For each request, find the minimum possible value of the final danger level. The requests do not affect each other.
Input Format
The input contains multiple test cases. The first line contains an integer $t$, the number of test cases, with $1\le t\le5000$. Then the test cases follow.
The first line of each test case contains two integers $n,q$, the number of inhabitants and the number of requests, with $1\le n,q\le35000$.
The second line contains $n$ integers $x_i$, the coordinates of the inhabitants, with $|x_i|\le10^8$.
The next $q$ lines describe the requests. Each line contains integers $k,r,a_1,\ldots,a_r$ in this order, where $k$ is the final total number of shelters, $r$ is the number of shelters whose positions are already fixed, and $a_j$ are the coordinates of these shelters, with $1\le k\le35000$, $0\le r\le k$, $|a_j|\le10^8$.
It is guaranteed that the sum of $n\cdot q$ over all test cases does not exceed $35000$, and the sum of $r$ over all requests does not exceed $35000$.
Output Format
For each test case, output one line containing $q$ real numbers, the answers to the requests in order. An answer is considered correct if its absolute or relative error compared to the standard answer does not exceed $10^{-9}$.
Explanation/Hint
For the first test case:
1. The first request needs only one shelter. It should be placed at the midpoint of positions $-5$ and $11$ of the leftmost and rightmost inhabitants. Both inhabitants are at distance $8$ from the shelter.
2. For the second request, the two shelters can be placed at the midpoint of $-5$ and $0$, and at the midpoint of $4$ and $11$.
3. For the third request, the shelters can be placed at $-3$, $2$, and $10$.
4. For the fourth request, just place one shelter at each inhabitant's position.
5. For the fifth request, just place the second shelter near the inhabitants at coordinates $10$ and $11$; then the maximum distance is the distance from the inhabitant at coordinate $-5$ to the shelter at coordinate $0$.
6. For the sixth request, one shelter can be added near coordinates $10$ and $11$, and another at coordinate $-2.5$.
Translated by QwenWork