CF1735E.House Planning
提高+/省选-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There are n houses in your city arranged on an axis at points h1,h2,…,hn. You want to build a new house for yourself and consider two options where to place it: points p1 and p2.
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 d1, d2: di,j=∣pi−hj∣, where ∣x∣ defines the absolute value of x.
After a long time of inactivity you have forgotten the locations of the houses h and the options p1, p2. But your diary still keeps two arrays — d1, d2, whose authenticity you doubt. Also, the values inside each array could be shuffled, so values at the same positions of d1 and d2 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 d1 correspond the distances from p1 to the houses, and in the array d2 — from p2 to the houses.
Also pay attention, that the locations of the houses hi and the considered options pj could match. For example, the next locations are correct: h=1,0,3,3, p=1,1, that could correspond to already shuffled d1=0,2,1,2, d2=2,2,1,0.
Check whether there are locations of houses h and considered points p1, p2, for which the founded arrays of distances would be correct. If it is possible, find appropriate locations of houses and considered options.
你的城市中有 n 座房屋,沿数轴排列在位置 h1,h2,…,hn 上。你想为自己新建一座房屋,并考虑两种选址方案:位置 p1 和 p2。
由于你喜欢拜访朋友,你已预先计算出这两种选址方案到所有现有房屋的距离。更准确地说,你计算出了两个数组 d1 和 d2:其中 di,j=∣pi−hj∣,∣x∣ 表示 x 的绝对值。
经过长时间的搁置,你已忘记了房屋位置 h 以及候选位置 p1、p2 的具体取值。但你的日记中仍保留着两个数组——d1 和 d2,而你对其真实性存疑。此外,每个数组内部的元素顺序可能已被打乱,即 d1 和 d2 中相同下标位置上的值可能对应于不同的房屋。请注意:一个数组中的数值不可能混入另一个数组,换言之,数组 d1 中的所有值均表示从 p1 到各房屋的距离,而数组 d2 中的所有值均表示从 p2 到各房屋的距离。
还需注意:房屋位置 hi 与候选位置 pj 可以重合。例如,以下情形是合法的:h={1,0,3,3},p={1,1},其对应已打乱的 d1={0,2,1,2}、d2={2,2,1,0}。
请判断是否存在一组房屋位置 h 和候选位置 p1、p2,使得所给定的距离数组 d1、d2 成立。若存在,请找出一组满足条件的房屋位置和候选位置。
输入格式
The first line of the input contains a single integer t (1≤t≤103) — the number of test cases. The description of test cases follows.
The first line of each test case contains one integer n (1≤n≤103) — the length of arrays d1, d2.
The next two lines contain n integers each: arrays d1 and d2 (0≤di,j≤109) respectively.
It is guaranteed that the sum of n over all test cases doesn't exceed 2⋅103.
输入的第一行包含一个整数 t(1≤t≤103),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤103),表示数组 d1 和 d2 的长度。
接下来的两行每行包含 n 个整数:分别为数组 d1 和 d2(0≤di,j≤109)。
保证所有测试用例中 n 的总和不超过 2⋅103。
输出格式
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 n integers h1,h2,…,hn. In the third line print two integers p1, p2.
It must be satisfied that 0≤hi,p1,p2≤2⋅109. 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"。第二行输出 n 个整数 h1,h2,…,hn。第三行输出两个整数 p1、p2。
需满足 0≤hi,p1,p2≤2⋅109。可以证明:若存在解,则必存在满足上述约束条件的解。
若存在多个解,输出任意一个即可。
输入输出样例
输入#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 1, the first planned house is located at point 0, the second at point 10. The existing house is located at point 5 and is at a distance of 5 from both planned houses.

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

In test case 3, the planned houses are located at points 33 and 69.

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

在下方图片中,您可以查看样例解。规划中的房屋以亮色显示:粉色和紫色;已存在的房屋则以暗色显示。
在测试用例 1 中,第一栋规划房屋位于坐标 0 处,第二栋位于坐标 10 处。已存在的房屋位于坐标 5 处,到两栋规划房屋的距离均为 5。

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

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

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

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