CF1721C.Min-Max Array Transformation
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a1,a2,…,an, which is sorted in non-descending order. You decided to perform the following steps to create array b1,b2,…,bn:
- Create an array d consisting of n arbitrary non-negative integers.
- Set bi=ai+di for each bi.
- Sort the array b in non-descending order.
You are given the resulting array b. For each index i, calculate what is the minimum and maximum possible value of di you can choose in order to get the given array b.
Note that the minimum (maximum) di-s are independent of each other, i. e. they can be obtained from different possible arrays d.
给你一个非降序排列的数组 a1,a2,…,an。你决定执行以下步骤来构造数组 b1,b2,…,bn:
- 创建一个由 n 个任意非负整数组成的数组 d;
- 对每个 i,令 bi=ai+di;
- 将数组 b 按非降序排序。
现在你得到了最终的数组 b。对每个下标 i,请计算:为得到给定的数组 b,所能选择的 di 的最小值和最大值分别是多少。
注意:各 di 的最小值(或最大值)彼此独立,即它们可能来自不同的可行数组 d。
输入格式
The first line contains the single integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains a single integer n (1≤n≤2⋅105) — the length of arrays a, b and d.
The second line contains n integers a1,a2,…,an (1≤ai≤109; ai≤ai+1) — the array a in non-descending order.
The third line contains n integers b1,b2,…,bn (1≤bi≤109; bi≤bi+1) — the array b in non-descending order.
Additional constraints on the input:
- there is at least one way to obtain the array b from the a by choosing an array d consisting of non-negative integers;
- the sum of n doesn't exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)—— 数组 a、b 和 d 的长度。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109;ai≤ai+1)—— 非降序排列的数组 a。
第三行包含 n 个整数 b1,b2,…,bn(1≤bi≤109;bi≤bi+1)—— 非降序排列的数组 b。
输入的额外约束:
- 至少存在一种方式,通过选择一个由非负整数组成的数组 d,从数组 a 得到数组 b;
- 所有测试用例中 n 的总和不超过 2⋅105。
输出格式
For each test case, print two lines. In the first line, print n integers d1min,d2min,…,dnmin, where dimin is the minimum possible value you can add to ai.
Secondly, print n integers d1max,d2max,…,dnmax, where dimax is the maximum possible value you can add to ai.
All dimin and dimax values are independent of each other. In other words, for each i, dimin is just the minimum value among all possible values of di.
对于每个测试用例,输出两行。
第一行输出 n 个整数 d1min,d2min,…,dnmin,其中 dimin 表示可加到 ai 上的最小可能值。
第二行输出 n 个整数 d1max,d2max,…,dnmax,其中 dimax 表示可加到 ai 上的最大可能值。
所有 dimin 和 dimax 的值彼此独立。换言之,对每个 i,dimin 仅表示所有可能的 di 值中的最小值。
输入输出样例
输入#1
4 3 2 3 5 7 11 13 1 1000 5000 4 1 2 3 4 1 2 3 4 4 10 20 30 40 22 33 33 55
输出#1
5 4 2 11 10 8 4000 4000 0 0 0 0 0 0 0 0 12 2 3 15 23 13 3 15
说明/提示
In the first test case, in order to get d1min=5, we can choose, for example, d=[5,10,6]. Then b = [2+5,3+10,5+6] = [7,13,11] = [7,11,13].
For d2min=4, we can choose d = [9,4,8]. Then b = [2+9,3+4,5+8] = [11,7,13] = [7,11,13].
在第一个测试用例中,为了得到 d1min=5,我们可以例如选择 d=[5,10,6]。此时 b=[2+5,3+10,5+6]=[7,13,11]=[7,11,13]。
对于 d2min=4,我们可以选择 d=[9,4,8]。此时 b=[2+9,3+4,5+8]=[11,7,13]=[7,11,13]。
输入解题思路,AI测评打分。不知道怎么写?