CF761D.Dasha and Very Difficult Problem

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Dasha logged into the system and began to solve problems. One of them is as follows:

Given two sequences a and b of length n each you need to write a sequence c of length n, the i-th element of which is calculated as follows: c__i = b__i - a__i.

About sequences a and b we know that their elements are in the range from l to r. More formally, elements satisfy the following conditions: l ≤ a__i ≤ r and l ≤ b__i ≤ r. About sequence c we know that all its elements are distinct.

Dasha wrote a solution to that problem quickly, but checking her work on the standard test was not so easy. Due to an error in the test system only the sequence a and the compressed sequence of the sequence c were known from that test.

Let's give the definition to a compressed sequence. A compressed sequence of sequence c of length n is a sequence p of length n, so that p__i equals to the number of integers which are less than or equal to c__i in the sequence c. For example, for the sequence c = [250, 200, 300, 100, 50] the compressed sequence will be p = [4, 3, 5, 2, 1]. Pay attention that in c all integers are distinct. Consequently, the compressed sequence contains all integers from 1 to n inclusively.

Help Dasha to find any sequence b for which the calculated compressed sequence of sequence c is correct.

达莎登录系统后开始解题。其中一题如下:

给定两个长度均为 nn 的序列 aa 和 bb,你需要构造一个长度为 nn 的序列 cc,其第 ii 个元素按如下方式计算:ci=bi−aic_i = b_i - a_i。

关于序列 aa 和 bb,已知它们的所有元素均在区间 [l,r][l, r] 内。更准确地说,所有元素满足如下条件:l≤ai≤rl \leq a_i \leq r 且 l≤bi≤rl \leq b_i \leq r。关于序列 cc,已知其所有元素互不相同。

达莎很快写出了该题的解法,但在标准测试用例上验证她的解答却并不容易。由于评测系统存在一个错误,该测试用例中仅提供了序列 aa 和序列 cc 的压缩序列。

下面我们定义“压缩序列”:对于长度为 nn 的序列 cc,其压缩序列为长度为 nn 的序列 pp,其中 pip_i 表示序列 cc 中小于等于 cic_i 的整数的个数。例如,对序列 c=[250, 200, 300, 100, 50]c = [250,\ 200,\ 300,\ 100,\ 50],其压缩序列为 p=[4, 3, 5, 2, 1]p = [4,\ 3,\ 5,\ 2,\ 1]。注意,由于 cc 中所有整数互不相同,因此压缩序列 pp 恰好包含从 11 到 nn 的所有整数(每个恰好出现一次)。

请帮助达莎找出任意一个满足条件的序列 bb,使得由此计算出的序列 cc 的压缩序列与给定的压缩序列一致。

输入格式

The first line contains three integers n, l, r (1 ≤ n ≤ 105, 1 ≤ l ≤ r ≤ 109) — the length of the sequence and boundaries of the segment where the elements of sequences a and b are.

The next line contains n integers _a_1,  _a_2,  ...,  a__n (l ≤ a__i ≤ r) — the elements of the sequence a.

The next line contains n distinct integers _p_1,  _p_2,  ...,  p__n (1 ≤ p__i ≤ n) — the compressed sequence of the sequence c.

第一行包含三个整数 nn、ll、rr(1 ≤ n ≤ 1051 ≤ n ≤ 10^5,1 ≤ l ≤ r ≤ 1091 ≤ l ≤ r ≤ 10^9)—— 分别表示序列的长度,以及序列 aa 和 bb 的元素取值范围 [l,r][l, r]。

下一行包含 nn 个整数 a1, a2, …, ana_1,\, a_2,\, \dots,\, a_n(l ≤ ai ≤ rl ≤ a_i ≤ r)—— 序列 aa 的元素。

再下一行包含 nn 个互不相同的整数 p1, p2, …, pnp_1,\, p_2,\, \dots,\, p_n(1 ≤ pi ≤ n1 ≤ p_i ≤ n)—— 序列 cc 的压缩表示。

输出格式

If there is no the suitable sequence b, then in the only line print "-1".

Otherwise, in the only line print n integers — the elements of any suitable sequence b.

如果不存在合适的序列 bb,则在唯一一行中输出 -1。

否则,在唯一一行中输出 nn 个整数——任意一个合适序列 bb 的元素。

输入输出样例

  • 输入#1

    5 1 5
    1 1 1 1 1
    3 1 5 4 2

    输出#1

    3 1 5 4 2
  • 输入#2

    4 2 9
    3 4 8 9
    3 2 1 4

    输出#2

    2 2 2 9
  • 输入#3

    6 1 5
    1 1 1 1 1 1
    2 3 5 4 1 6

    输出#3

    -1

说明/提示

Sequence b which was found in the second sample is suitable, because calculated sequence c = [2 - 3, 2 - 4, 2 - 8, 9 - 9] = [ - 1,  - 2,  - 6, 0] (note that c__i = b__i - a__i) has compressed sequence equals to p = [3, 2, 1, 4].

第二个样例中找到的序列 bb 是合适的,因为计算得到的序列 c=[2−3, 2−4, 2−8, 9−9]=[−1, −2, −6, 0]c = [2 - 3,\ 2 - 4,\ 2 - 8,\ 9 - 9] = [-1,\ -2,\ -6,\ 0](注意 ci=bi−aic_i = b_i - a_i)的压缩序列等于 p=[3, 2, 1, 4]p = [3,\ 2,\ 1,\ 4]。

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

首页