This is the easy version of the problem. The only differences between the two versions…
- User
This is the easy version of the problem. The only differences between the two versions are the constraints on m and q . In this version, m=2 and q=1 . You can make hacks only if both versions of the problem are solved.
Narek and Tsovak were busy preparing this round, so they have not managed to do their homework and decided to steal David's homework. Their strict teacher noticed that David has no homework and now wants to punish him. She hires other teachers to help her catch David. And now m teachers together are chasing him. Luckily, the classroom is big, so David has many places to hide.
The classroom can be represented as a one-dimensional line with cells from 1 to n , inclusive.
At the start, all m teachers and David are in distinct cells. Then they make moves. During each move
David goes to an adjacent cell or stays at the current one. Then, each of the m teachers simultaneously goes to an adjacent cell or stays at the current one. This continues until David is caught. David is caught if any of the teachers (possibly more than one) is located in the same cell as David. Everyone sees others' moves, so they all act optimally.
Your task is to find how many moves it will take for the teachers to catch David if they all act optimally.
Acting optimally means the student makes his moves in a way that maximizes the number of moves the teachers need to catch him; and the teachers coordinate with each other to make their moves in a way that minimizes the number of moves they need to catch the student.
Also, as Narek and Tsovak think this task is easy, they decided to give you q queries on David's position. Note: this is the easy version, and you are given only one query.
Input In the first line of the input, you are given a single integer t (1≤t≤105 ) — the number of test cases. The description of each test case follows.
In the first line of each test case, you are given three integers n , m , and q (3≤n≤109 , m=2 , q=1 ) — the number of cells on the line, the number of teachers, and the number of queries.
In the second line of each test case, you are given m distinct integers b1,b2,…,bm (1≤bi≤n ) — the cell numbers of the teachers.
In the third line of each test case, you are given q integers a1,a2,…,aq (1≤ai≤n ) — David's cell number for every query.
It is guaranteed that for any i , j such that 1≤i≤m and 1≤j≤q , bi≠aj .
Output For each test case, output q lines, the i -th of them containing the answer of the i -th query.
- Assistant
To solve this problem, we need to determine the minimum number of moves required for the teachers to catch David, given their starting positions and David's starting position. The key observations are:
-
Teachers Move After David: After David makes his move (which the teachers see), each teacher can move to an adjacent cell or stay in their current cell. Their primary goal is to minimize the number of moves required to catch David.
-
Minimum Distance Matters: The minimal number of moves required is equal to the minimal initial distance between David and any of the teachers. This is because the teacher closest to David can reach him in as many moves as there are units of distance between them.
-
David's Optimal Play: David wants to maximize the minimal number of moves, but he can't change the initial positions. So, the earliest he'll be caught is in the minimal initial distance.
-