CF1721C.Min-Max Array Transformation
普及/提高-
通过率:0%
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 .
输入格式
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 .
输出格式
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 .
输入输出样例
输入#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] .