CF1735E.House Planning

提高+/省选-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There are nn houses in your city arranged on an axis at points h1,h2,…,hnh_1, h_2, \ldots, h_n. You want to build a new house for yourself and consider two options where to place it: points p1p_1 and p2p_2.

As you like visiting friends, you have calculated in advance the distances from both options to all existing houses. More formally, you have calculated two arrays d1d_1, d2d_2: di,j=∣pi−hj∣d_{i, j} = \left|p_i - h_j\right|, where ∣x∣|x| defines the absolute value of xx.

After a long time of inactivity you have forgotten the locations of the houses hh and the options p1p_1, p2p_2. But your diary still keeps two arrays — d1d_1, d2d_2, whose authenticity you doubt. Also, the values inside each array could be shuffled, so values at the same positions of d1d_1 and d2d_2 may correspond to different houses. Pay attention, that values from one array could not get to another, in other words, all values in the array d1d_1 correspond the distances from p1p_1 to the houses, and in the array d2d_2 — from p2p_2 to the houses.

Also pay attention, that the locations of the houses hih_i and the considered options pjp_j could match. For example, the next locations are correct: h=1,0,3,3h = {1, 0, 3, 3}, p=1,1p = {1, 1}, that could correspond to already shuffled d1=0,2,1,2d_1 = {0, 2, 1, 2}, d2=2,2,1,0d_2 = {2, 2, 1, 0}.

Check whether there are locations of houses hh and considered points p1p_1, p2p_2, for which the founded arrays of distances would be correct. If it is possible, find appropriate locations of houses and considered options.

你的城市中有 nn 座房屋,沿数轴排列在位置 h1,h2,…,hnh_1, h_2, \ldots, h_n 上。你想为自己新建一座房屋,并考虑两种选址方案:位置 p1p_1 和 p2p_2。

由于你喜欢拜访朋友,你已预先计算出这两种选址方案到所有现有房屋的距离。更准确地说,你计算出了两个数组 d1d_1 和 d2d_2:其中 di,j=∣pi−hj∣d_{i, j} = \left|p_i - h_j\right|,∣x∣|x| 表示 xx 的绝对值。

经过长时间的搁置,你已忘记了房屋位置 hh 以及候选位置 p1p_1、p2p_2 的具体取值。但你的日记中仍保留着两个数组——d1d_1 和 d2d_2,而你对其真实性存疑。此外,每个数组内部的元素顺序可能已被打乱,即 d1d_1 和 d2d_2 中相同下标位置上的值可能对应于不同的房屋。请注意:一个数组中的数值不可能混入另一个数组,换言之,数组 d1d_1 中的所有值均表示从 p1p_1 到各房屋的距离,而数组 d2d_2 中的所有值均表示从 p2p_2 到各房屋的距离。

还需注意:房屋位置 hih_i 与候选位置 pjp_j 可以重合。例如,以下情形是合法的:h={1,0,3,3}h = \{1, 0, 3, 3\},p={1,1}p = \{1, 1\},其对应已打乱的 d1={0,2,1,2}d_1 = \{0, 2, 1, 2\}、d2={2,2,1,0}d_2 = \{2, 2, 1, 0\}。

请判断是否存在一组房屋位置 hh 和候选位置 p1p_1、p2p_2,使得所给定的距离数组 d1d_1、d2d_2 成立。若存在,请找出一组满足条件的房屋位置和候选位置。

输入格式

The first line of the input contains a single integer tt (1≤t≤1031 \le t \le 10^3) — the number of test cases. The description of test cases follows.

The first line of each test case contains one integer nn (1≤n≤1031 \le n \le 10^3) — the length of arrays d1d_1, d2d_2.

The next two lines contain nn integers each: arrays d1d_1 and d2d_2 (0≤di,j≤1090 \le d_{i, j} \le 10^9) respectively.

It is guaranteed that the sum of nn over all test cases doesn't exceed 2⋅1032 \cdot 10^3.

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

每个测试用例的第一行包含一个整数 nn(1≤n≤1031 \le n \le 10^3),表示数组 d1d_1 和 d2d_2 的长度。

接下来的两行每行包含 nn 个整数:分别为数组 d1d_1 和 d2d_2(0≤di,j≤1090 \le d_{i, j} \le 10^9)。

保证所有测试用例中 nn 的总和不超过 2⋅1032 \cdot 10^3。

输出格式

For each test case, output a single line "NO" if there is no answer.

Otherwise output three lines. The first line must contain "YES". In the second line, print nn integers h1,h2,…,hnh_1, h_2, \ldots, h_n. In the third line print two integers p1p_1, p2p_2.

It must be satisfied that 0≤hi,p1,p2≤2⋅1090 \le h_i, p_1, p_2 \le 2 \cdot 10^9. We can show that if there is an answer, then there is one satisfying these constraints.

If there are several answers, output any of them.

对于每个测试用例,若无解,则输出一行 "NO"。

否则输出三行。第一行必须为 "YES"。第二行输出 nn 个整数 h1,h2,…,hnh_1, h_2, \ldots, h_n。第三行输出两个整数 p1p_1、p2p_2。

需满足 0≤hi,p1,p2≤2⋅1090 \le h_i, p_1, p_2 \le 2 \cdot 10^9。可以证明:若存在解,则必存在满足上述约束条件的解。

若存在多个解,输出任意一个即可。

输入输出样例

  • 输入#1

    4
    1
    5
    5
    2
    10 12
    5 20
    2
    10 33
    26 69
    4
    0 2 1 2
    2 2 1 0

    输出#1

    YES
    5 
    0 10
    NO
    YES
    0 43 
    33 69
    YES
    1 0 3 3
    1 1

说明/提示

In the image below you can see the sample solutions. Planned houses are shown in bright colours: pink and purple. Existing houses are dim.

In test case 11, the first planned house is located at point 00, the second at point 1010. The existing house is located at point 55 and is at a distance of 55 from both planned houses.

It can be shown that there is no answer for test case 22.

In test case 33, the planned houses are located at points 3333 and 6969.

Note that in test case 44, both plans are located at point 11, where one of the existing houses is located at the same time. It is a correct placement.

在下方图片中,您可以查看样例解。规划中的房屋以亮色显示:粉色和紫色;已存在的房屋则以暗色显示。

在测试用例 11 中,第一栋规划房屋位于坐标 00 处,第二栋位于坐标 1010 处。已存在的房屋位于坐标 55 处,到两栋规划房屋的距离均为 55。

可以证明:测试用例 22 无解。

在测试用例 33 中,规划房屋位于坐标 3333 和 6969 处。

注意,在测试用例 44 中,两栋规划房屋均位于坐标 11 处,而恰好有一栋已存在的房屋也位于该位置。这是一种合法的布置方式。

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

首页