Codeforces Round 823 (Div. 2)

96 阅读2分钟

B. Meeting on the Line

n people live on the coordinate line, the i-th one lives at the point xi (1≤i≤n). They want to choose a position x0 to meet. The i-th person will spend |xi−x0| minutes to get to the meeting place. Also, the i-th person needs ti minutes to get dressed, so in total he or she needs ti+|xi−x0| minutes.

Here |y| denotes the absolute value of y.

These people ask you to find a position x0 that minimizes the time in which all n people can gather at the meeting place.

Input

The first line contains a single integer t (1≤t≤103) — the number of test cases. Then the test cases follow.

Each test case consists of three lines.

The first line contains a single integer n (1≤n≤105) — the number of people.

The second line contains n integers x1,x2,…,xn  (0≤xi≤108 ) — the positions of the people.

The third line contains n integers t1,t2,…,tn(0≤ti≤108), where ti is the time i-th person needs to get dressed.

It is guaranteed that the sum of n over all test cases does not exceed 2⋅1052⋅105.

Output

For each test case, print a single real number — the optimum position x0. It can be shown that the optimal position x0 is unique.

Your answer will be considered correct if its absolute or relative error does not exceed 10−610−6. Formally, let your answer be a, the jury's answer be b. Your answer will be considered correct if |a−b|max(1,|b|)≤10−6.

Example

input

Copy

7
1
0
3
2
3 1
0 0
2
1 4
0 0
3
1 2 3
0 0 0
3
1 2 3
4 1 2
3
3 3 3
5 3 3
6
5 4 7 2 10 4
3 2 5 1 4 6

output

Copy

0
2
2.5
2
1
3
6

Note

  • In the 1-st test case there is one person, so it is efficient to choose his or her position for the meeting place. Then he or she will get to it in 3 minutes, that he or she need to get dressed.
  • In the 2-nd test case there are 2 people who don't need time to get dressed. Each of them needs one minute to get to position 2.
  • In the 5-th test case the 11-st person needs 4 minutes to get to position 1 (4 minutes to get dressed and 0 minutes on the way); the 2-nd person needs 2 minutes to get to position 1 (1 minute to get dressed and 1 minute on the way); the 3-rd person needs 4 minutes to get to position 1 (2 minutes to get dressed and 2 minutes on the way).

题意:

给你两个序列让你找一个点使得到这个点花的时间的最大值最小

代码:

double check(double mid)
{
    double l = -2e18, r = 2e18;
    for(int i = 1 ; i <= n ; i ++ )
    {
        if(mid <= t[i]) return false;
        else {
            l = max(l, a[i] + t[i] - mid);
            r = min(r, a[i] + mid - t[i]);
        }
    }
    ans = l;
    return r >= l - 1e-8;
}

void solve()
{
    cin >> n;
    double maxv = 0;
    for(int i = 1 ; i <= n ; i ++ ) cin >> a[i];
    for(int i = 1 ; i <= n ; i ++ ) cin >> t[i];
    double l = 0, r = 2e18;
    for(int i = 1 ; i <= 100 ; i ++ )
    {
            double mid = (l + r) / 2;
            if(check(mid)) r = mid;
            else l = mid;
    }
    check(r);
    printf("%.10lf\n", fabs(ans));
}