CF1721C.Min-Max Array Transformation

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

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.

给你一个非降序排列的数组 a1,a2,…,ana_1, a_2, \dots, a_n。你决定执行以下步骤来构造数组 b1,b2,…,bnb_1, b_2, \dots, b_n:

  1. 创建一个由 nn 个任意非负整数组成的数组 dd;
  2. 对每个 ii,令 bi=ai+dib_i = a_i + d_i;
  3. 将数组 bb 按非降序排序。

现在你得到了最终的数组 bb。对每个下标 ii,请计算:为得到给定的数组 bb,所能选择的 did_i 的最小值和最大值分别是多少。

注意:各 did_i 的最小值(或最大值)彼此独立,即它们可能来自不同的可行数组 dd。

输入格式

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

The first line of each test case contains a single integer nn (1≤n≤2⋅1051 \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 (1≤ai≤1091 \le a_i \le 10^9; ai≤ai+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 (1≤bi≤1091 \le b_i \le 10^9; bi≤bi+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 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤2⋅1051 \le n \le 2 \cdot 10^5)—— 数组 aa、bb 和 dd 的长度。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1091 \le a_i \le 10^9;ai≤ai+1a_i \le a_{i+1})—— 非降序排列的数组 aa。

第三行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \dots, b_n(1≤bi≤1091 \le b_i \le 10^9;bi≤bi+1b_i \le b_{i+1})—— 非降序排列的数组 bb。

输入的额外约束:

  • 至少存在一种方式,通过选择一个由非负整数组成的数组 dd,从数组 aa 得到数组 bb;
  • 所有测试用例中 nn 的总和不超过 2⋅1052 \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.

对于每个测试用例,输出两行。
第一行输出 nn 个整数 d1min,d2min,…,dnmind_1^{min}, d_2^{min}, \dots, d_n^{min},其中 dimind_i^{min} 表示可加到 aia_i 上的最小可能值。

第二行输出 nn 个整数 d1max,d2max,…,dnmaxd_1^{max}, d_2^{max}, \dots, d_n^{max},其中 dimaxd_i^{max} 表示可加到 aia_i 上的最大可能值。

所有 dimind_i^{min} 和 dimaxd_i^{max} 的值彼此独立。换言之,对每个 ii,dimind_i^{min} 仅表示所有可能的 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].

在第一个测试用例中,为了得到 d1min=5d_1^{min} = 5,我们可以例如选择 d=[5,10,6]d = [5, 10, 6]。此时 b=[2+5,3+10,5+6]=[7,13,11]=[7,11,13]b = [2+5,3+10,5+6] = [7,13,11] = [7,11,13]。

对于 d2min=4d_2^{min} = 4,我们可以选择 d=[9,4,8]d = [9, 4, 8]。此时 b=[2+9,3+4,5+8]=[11,7,13]=[7,11,13]b = [2+9,3+4,5+8] = [11,7,13] = [7,11,13]。

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

首页