CF1730B.Meeting on the Line

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

nn people live on the coordinate line, the ii -th one lives at the point xix_i ( 1in1 \le i \le n ). They want to choose a position x0x_0 to meet. The ii -th person will spend xix0|x_i - x_0| minutes to get to the meeting place. Also, the ii -th person needs tit_i minutes to get dressed, so in total he or she needs ti+xix0t_i + |x_i - x_0| minutes.

Here y|y| denotes the absolute value of yy .

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

输入格式

The first line contains a single integer tt ( 1t1031 \le t \le 10^3 ) — the number of test cases. Then the test cases follow.

Each test case consists of three lines.

The first line contains a single integer nn ( 1n1051 \le n \le 10^5 ) — the number of people.

The second line contains nn integers x1,x2,,xnx_1, x_2, \dots, x_n ( 0xi1080 \le x_i \le 10^{8} ) — the positions of the people.

The third line contains nn integers t1,t2,,tnt_1, t_2, \dots, t_n ( 0ti1080 \le t_i \le 10^{8} ), where tit_i is the time ii -th person needs to get dressed.

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10^5 .

输出格式

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

Your answer will be considered correct if its absolute or relative error does not exceed 10610^{−6} . Formally, let your answer be aa , the jury's answer be bb . Your answer will be considered correct if abmax(1,b)106\frac{|a−b|}{max(1,|b|)} \le 10^{−6} .

输入输出样例

  • 输入#1

    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

    输出#1

    0
    2
    2.5
    2
    1
    3
    6

说明/提示

  • In the 11 -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 33 minutes, that he or she need to get dressed.
  • In the 22 -nd test case there are 22 people who don't need time to get dressed. Each of them needs one minute to get to position 22 .
  • In the 55 -th test case the 11 -st person needs 44 minutes to get to position 11 ( 44 minutes to get dressed and 00 minutes on the way); the 22 -nd person needs 22 minutes to get to position 11 ( 11 minute to get dressed and 11 minute on the way); the 33 -rd person needs 44 minutes to get to position 11 ( 22 minutes to get dressed and 22 minutes on the way).
首页