Mice V2
Difficulty: Hard

__n__ mice are playing in the desert, when one of them notices some hawks flying in the sky. It alerts the other mice who now realize that the hawks are going to attack them very soon. They are scared and want to get inside holes to ensure their safety.<br>
Mice and holes are placed on a straight line. There are __m__ holes on this line. Each hole can accommodate only 1 mouse. A mouse can either stay at its position, or move one step right from __x__ to __x+1__, or move one step left from __x__ to __x-1__. Any of these movements takes 1 minute. <br>
Assign mice to holes so that the time required for all the mice to move inside the holes is minimized. 

__Input Format__ <br>
The first line contains an integer __T__, the number of test cases. This is followed by __T__ blocks of input: <br>  
First line contains 2 positive integers **n** and **m** separated by a single space.   
Next line contains __n__ space separated integers, denoting the positions of the mice.  
Next line contains __m__ space separated integers, denoting the positions of the holes.  
Note: No two holes have the same position.  

__Output Format__ <br>
For each testcase, print the minimum time taken by all the mice to reach inside the holes.

__Constraints__ <br>
1 ≤ T ≤ 17 <br>
1 ≤ n ≤ 131072 <br>
1 ≤ m ≤ 131072 <br>
n ≤ m <br>
-10<sup>8</sup> ≤ mouse[i] ≤ 10<sup>8</sup> <br>
-10<sup>8</sup> ≤ hole[j] ≤ 10<sup>8</sup> <br>


__Sample Input__ <br>
<pre>
1
3 4
2 0 -4
3 1 2 -1
</pre>

__Sample Output__ <br>
<pre>
3
</pre>

**Explanation**  
One possible solution is : <br>
Assign mouse at position x=-4 to hole at position x=-1  -> 3 minutes <br>
Assign mouse at postion x=2 to hole at position x=2  -> 0 minutes <br>
Assign mouse at postion x=0 to hole at postion x=3  -> 3 minutes <br>
So the answer is 3, after 3 minutes all of the mice are in the holes.

Input Format:

Output Format:

Sample Input:

Sample Output:

Python 3 starter code:


Reference solution (Unknown):
    const ll N = (1<<17)+10;

    int a[N];
    int b[N];
    int n, m;

    bool check(int tt)
    {
        int i = 0;
        int j = 0;
        while(i < n && j < m)
        {
            if(abs(a[i]-b[j]) <= tt)
            {
                i ++;
                j ++;
            }
            else
            {
                j ++;
            }
        }

        if(i == n)
            return true;
        else
            return false;
    }


    int main()
    {
        int test;

        scanf("%d", &test);
        for(int cas = 1; cas <= test; cas ++)
        {			
            scanf("%d %d", &n, &m);
            for(int i = 0; i < n; i ++)
                scanf("%d", &a[i]);

            for(int i = 0; i < m; i ++)
                scanf("%d", &b[i]);

            sort(a, a+n);
            sort(b, b+m);

            int L = 0;
            int R = 210000000;
            int mid;
            while(L < R)
            {
                mid = (L+R)/2;
                if(check(mid) == true)
                    R = mid;
                else
                    L = mid+1;
            }

            printf("%d\n", L);
        }

        return 0;
    }