CF1305A.Kuroni and the Gifts
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Kuroni has n daughters. As gifts for them, he bought n necklaces and n bracelets:
- the i-th necklace has a brightness ai, where all the ai are pairwise distinct (i.e. all ai are different),
- the i-th bracelet has a brightness bi, where all the bi are pairwise distinct (i.e. all bi are different).
Kuroni wants to give exactly one necklace and exactly one bracelet to each of his daughters. To make sure that all of them look unique, the total brightnesses of the gifts given to each daughter should be pairwise distinct. Formally, if the i-th daughter receives a necklace with brightness xi and a bracelet with brightness yi, then the sums xi+yi should be pairwise distinct. Help Kuroni to distribute the gifts.
For example, if the brightnesses are a=[1,7,5] and b=[6,1,2], then we may distribute the gifts as follows:
- Give the third necklace and the first bracelet to the first daughter, for a total brightness of a3+b1=11.
- Give the first necklace and the third bracelet to the second daughter, for a total brightness of a1+b3=3.
- Give the second necklace and the second bracelet to the third daughter, for a total brightness of a2+b2=8.
Here is an example of an invalid distribution:
- Give the first necklace and the first bracelet to the first daughter, for a total brightness of a1+b1=7.
- Give the second necklace and the second bracelet to the second daughter, for a total brightness of a2+b2=8.
- Give the third necklace and the third bracelet to the third daughter, for a total brightness of a3+b3=7.
This distribution is invalid, as the total brightnesses of the gifts received by the first and the third daughter are the same. Don't make them this upset!
库洛尼有 n 个女儿。作为礼物,他买了 n 条项链和 n 条手链:
- 第 i 条项链的亮度为 ai,且所有 ai 两两不同(即所有 ai 均互不相同);
- 第 i 条手链的亮度为 bi,且所有 bi 两两不同(即所有 bi 均互不相同)。
库洛尼希望给每个女儿恰好一条项链和一条手链。为了确保每位女儿看起来都独一无二,每位女儿所获礼物的总亮度必须两两不同。形式化地说,若第 i 位女儿收到亮度为 xi 的项链和亮度为 yi 的手链,则所有和 xi+yi 必须两两不同。请帮助库洛尼完成礼物分配。
例如,若亮度分别为 a=[1,7,5] 和 b=[6,1,2],则可如下分配礼物:
- 将第三条项链与第一条手链分给第一位女儿,总亮度为 a3+b1=11;
- 将第一条项链与第三条手链分给第二位女儿,总亮度为 a1+b3=3;
- 将第二条项链与第二条手链分给第三位女儿,总亮度为 a2+b2=8。
以下是一种无效的分配方式:
- 将第一条项链与第一条手链分给第一位女儿,总亮度为 a1+b1=7;
- 将第二条项链与第二条手链分给第二位女儿,总亮度为 a2+b2=8;
- 将第三条项链与第三条手链分给第三位女儿,总亮度为 a3+b3=7。
该分配方式无效,因为第一位和第三位女儿所获礼物的总亮度相同。千万别让她们因此而伤心!
输入格式
The input consists of multiple test cases. The first line contains an integer t (1≤t≤100) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer n (1≤n≤100) — the number of daughters, necklaces and bracelets.
The second line of each test case contains n distinct integers a1,a2,…,an (1≤ai≤1000) — the brightnesses of the necklaces.
The third line of each test case contains n distinct integers b1,b2,…,bn (1≤bi≤1000) — the brightnesses of the bracelets.
输入包含多个测试用例。第一行包含一个整数 t(1≤t≤100),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤100),表示女儿、项链和手链的数量。
每个测试用例的第二行包含 n 个互不相同的整数 a1,a2,…,an(1≤ai≤1000),表示各条项链的亮度。
每个测试用例的第三行包含 n 个互不相同的整数 b1,b2,…,bn(1≤bi≤1000),表示各条手链的亮度。
输出格式
For each test case, print a line containing n integers x1,x2,…,xn, representing that the i-th daughter receives a necklace with brightness xi. In the next line print n integers y1,y2,…,yn, representing that the i-th daughter receives a bracelet with brightness yi.
The sums x1+y1,x2+y2,…,xn+yn should all be distinct. The numbers x1,…,xn should be equal to the numbers a1,…,an in some order, and the numbers y1,…,yn should be equal to the numbers b1,…,bn in some order.
It can be shown that an answer always exists. If there are multiple possible answers, you may print any of them.
对于每个测试用例,输出一行包含 n 个整数 x1,x2,…,xn,表示第 i 位女儿收到一条亮度为 xi 的项链;
下一行输出 n 个整数 y1,y2,…,yn,表示第 i 位女儿收到一条亮度为 yi 的手链。
和 x1+y1,x2+y2,…,xn+yn 应互不相同。
数 x1,…,xn 应为 a1,…,an 的某个排列,
数 y1,…,yn 应为 b1,…,bn 的某个排列。
可以证明答案一定存在。若存在多个可能的答案,输出任意一个即可。
输入输出样例
输入#1
2 3 1 8 5 8 4 5 3 1 7 5 6 1 2
输出#1
1 8 5 8 4 5 5 1 7 6 2 1
说明/提示
In the first test case, it is enough to give the i-th necklace and the i-th bracelet to the i-th daughter. The corresponding sums are 1+8=9, 8+4=12, and 5+5=10.
The second test case is described in the statement.
在第一个测试用例中,只需将第 i 条项链和第 i 条手链分配给第 i 个女儿即可。对应的和分别为 1+8=9、8+4=12 和 5+5=10。
第二个测试用例已在题目描述中给出。
输入解题思路,AI测评打分。不知道怎么写?