CF1730B.Meeting on the Line

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

nn people live on the coordinate line, the ii-th one lives at the point xix_i (1≤i≤n1 \le i \le n). They want to choose a position x0x_0 to meet. The ii-th person will spend ∣xi−x0∣|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+∣xi−x0∣t_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.

有 nn 个人住在数轴上,其中第 ii 个人住在坐标点 xix_i 处(1≤i≤n1 \le i \le n)。他们希望选择一个位置 x0x_0 作为集会地点。第 ii 个人到达该集会地点需要花费 ∣xi−x0∣|x_i - x_0| 分钟。此外,第 ii 个人还需要 tit_i 分钟整理着装,因此其总耗时为 ti+∣xi−x0∣t_i + |x_i - x_0| 分钟。

此处 ∣y∣|y| 表示 yy 的绝对值。

这些人请你找出一个位置 x0x_0,使得所有 nn 个人均能到达集会地点所需的时间(即所有人中最大耗时)最小化。

输入格式

The first line contains a single integer tt (1≤t≤1031 \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 (1≤n≤1051 \le n \le 10^5) — the number of people.

The second line contains nn integers x1,x2,…,xnx_1, x_2, \dots, x_n (0≤xi≤1080 \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 (0≤ti≤1080 \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 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1031 \le t \le 10^3),表示测试用例的数量。随后是各测试用例。

每个测试用例由三行组成。

第一行包含一个整数 nn(1≤n≤1051 \le n \le 10^5),表示人数。

第二行包含 nn 个整数 x1,x2,…,xnx_1, x_2, \dots, x_n(0≤xi≤1080 \le x_i \le 10^{8}),表示各个人的位置。

第三行包含 nn 个整数 t1,t2,…,tnt_1, t_2, \dots, t_n(0≤ti≤1080 \le t_i \le 10^{8}),其中 tit_i 表示第 ii 个人穿衣所需的时间。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \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 10−610^{−6}. Formally, let your answer be aa, the jury's answer be bb. Your answer will be considered correct if ∣a−b∣max(1,∣b∣)≤10−6\frac{|a−b|}{max(1,|b|)} \le 10^{−6}.

对于每个测试用例,输出一个实数——最优位置 x0x_0。可以证明最优位置 x0x_0 是唯一的。

若你的答案的绝对误差或相对误差不超过 10−610^{−6},则视为正确。形式化地,设你的答案为 aa,评测组的答案为 bb,当且仅当 ∣a−b∣max⁡(1,∣b∣)≤10−6\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).

  • 在第 11 个测试用例中,只有一个人,因此选择他或她的位置作为会议地点是最优的。此时,他或她需要 33 分钟到达该地点(全部用于穿衣)。

  • 在第 22 个测试用例中,有 22 个人,他们均无需穿衣时间。每人到达位置 22 均需 11 分钟。

  • 在第 55 个测试用例中,第 11 个人到达位置 11 需要 44 分钟(其中 44 分钟用于穿衣,路上耗时 00 分钟);第 22 个人到达位置 11 需要 22 分钟(其中 11 分钟用于穿衣,路上耗时 11 分钟);第 33 个人到达位置 11 需要 44 分钟(其中 22 分钟用于穿衣,路上耗时 22 分钟)。

输入解题思路,AI测评打分。不知道怎么写?

首页