CF1721C.Min-Max Array Transformation

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given an array a1,a2,,ana_1, a_2, \dots, a_n , which is sorted in non-descending order. You decided to perform the following steps to create array b1,b2,,bnb_1, b_2, \dots, b_n :

  1. Create an array dd consisting of nn arbitrary non-negative integers.
  2. Set bi=ai+dib_i = a_i + d_i for each bib_i .
  3. Sort the array bb in non-descending order.

You are given the resulting array bb . For each index ii , calculate what is the minimum and maximum possible value of did_i you can choose in order to get the given array bb .

Note that the minimum (maximum) did_i -s are independent of each other, i. e. they can be obtained from different possible arrays dd .

输入格式

The first line contains the single integer tt ( 1t1041 \le t \le 10^4 ) — the number of test cases.

The first line of each test case contains a single integer nn ( 1n21051 \le n \le 2 \cdot 10^5 ) — the length of arrays aa , bb and dd .

The second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n ( 1ai1091 \le a_i \le 10^9 ; aiai+1a_i \le a_{i+1} ) — the array aa in non-descending order.

The third line contains nn integers b1,b2,,bnb_1, b_2, \dots, b_n ( 1bi1091 \le b_i \le 10^9 ; bibi+1b_i \le b_{i+1} ) — the array bb in non-descending order.

Additional constraints on the input:

  • there is at least one way to obtain the array bb from the aa by choosing an array dd consisting of non-negative integers;
  • the sum of nn doesn't exceed 21052 \cdot 10^5 .

输出格式

For each test case, print two lines. In the first line, print nn integers d1min,d2min,,dnmind_1^{min}, d_2^{min}, \dots, d_n^{min} , where dimind_i^{min} is the minimum possible value you can add to aia_i .

Secondly, print nn integers d1max,d2max,,dnmaxd_1^{max}, d_2^{max}, \dots, d_n^{max} , where dimaxd_i^{max} is the maximum possible value you can add to aia_i .

All dimind_i^{min} and dimaxd_i^{max} values are independent of each other. In other words, for each ii , dimind_i^{min} is just the minimum value among all possible values of did_i .

输入输出样例

  • 输入#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=5d_1^{min} = 5 , we can choose, for example, d=[5,10,6]d = [5, 10, 6] . Then bb == [2+5,3+10,5+6][2+5,3+10,5+6] == [7,13,11][7,13,11] == [7,11,13][7,11,13] .

For d2min=4d_2^{min} = 4 , we can choose dd == [9,4,8][9, 4, 8] . Then bb == [2+9,3+4,5+8][2+9,3+4,5+8] == [11,7,13][11,7,13] == [7,11,13][7,11,13] .

首页