time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard output

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: ci = bi - ai.

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 ≤ ai ≤ r and l ≤ bi ≤ 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 pi equals to the number of integers which are less than or equal to ci 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.

Input

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 a1,  a2,  …,  an (l ≤ ai ≤ r) — the elements of the sequence a.

The next line contains n distinct integers p1,  p2,  …,  pn (1 ≤ pi ≤ n) — the compressed sequence of the sequence c.

Output

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.

Examples

input

5 1 5

1 1 1 1 1

3 1 5 4 2

output

3 1 5 4 2

input

4 2 9

3 4 8 9

3 2 1 4

output

2 2 2 9

input

6 1 5

1 1 1 1 1 1

2 3 5 4 1 6

output

-1

Note

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 ci = bi - ai) has compressed sequence equals to p = [3, 2, 1, 4].

【题目链接】:http://codeforces.com/contest/761/problem/D

【题解】



因为

c[i] = b[i]-a[i];

题目所给的p[i]实际上是c[i]之间的大小关系;

p[i]=1是最小的,p[i]=2则是第二小…p[i]=n则是最大的;

这样我们可以让

c的值从小到大为

c[1],c[1]+1,c[1]+2,c[1]+3…c[1]+n-1;

即每个值递增1

这样能够在满足p[]数组的情况下尽可能地让c[i]小,相应的b[i]也就小了

但是有可能我们要求c[i]为递增的规律的时候;

b[i]是根据c[i]求出来的

某个i会出现

b[i]< l

这个时候让b[i]为l(b数组没有说一定要全都不同)

然后c[i]相应地调整;

c[i]会变大一点,这样能保证满足p数组,同时b[i]还是最小的l,所以还是能够保证c[i]此时也是最小的

(但是如果b[i]>r,则直接输出无解;

因为此前的操作我们已经尽可能的让c数组小了;

如果还不行(即b[i]还是太大),那么就无解了;)

然后再从i+1开始



c[i+1]=c[i]+1

c[i+2] = c[i]+2



即此后每个值还是递增1

然后求出相应的b数组

(所以这个c数组最后可能中间会有不是c[i]=c[i-1]+1的断层);

一开始的时候设最小的c的下标为idx

让b[idx]=l;(这样能保证b数组、c数组一开始是最小的了)

求出这个时候的c[idx]作为发生器;

然后做上面的过程就好;

贪心点就是时刻保证c、b数组是最小的,这样b数组在某个时刻通过c数组获得的时候,如果大于r则肯定无解;

小于l则可以调整为l,还是保证c、b为最小的;



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int MAXN = 1e5+100; int a[MAXN],n,l,r,cc[MAXN],b[MAXN],c[MAXN]; void wujie()
{
puts("-1");
exit(0);
} int main()
{
//freopen("F:\\rush.txt","r",stdin);
cin >> n >> l >> r;
rep1(i,1,n)
rei(a[i]);
rep1(i,1,n)
{
int x;
rei(x);
cc[x] = i;
}
//c[i] = b[i]-a[i];
//c[idx]>c[1]
//b[idx]-a[idx]>b[1]-a[1];
//c[i]+a[i] = b[i];
b[cc[1]] = l;
c[cc[1]] = b[cc[1]]-a[cc[1]];
int temp = b[cc[1]]-a[cc[1]];
rep1(i,2,n)
{
int idx = cc[i];
//
c[idx] = temp+1;
b[idx] = c[idx]+a[idx];
temp++;
if (b[idx]<l)
{
b[idx] = l;
temp = b[idx]-a[idx];
}
if (b[idx]>r)
wujie();
}
for (int i = 1;i <= n;i++)
{
printf("%d",b[i]);
if (i==n)
puts("");
else
putchar(' ');
}
return 0;
}

【codeforces 761D】Dasha and Very Difficult Problem的更多相关文章

  1. 【codeforces 761A】Dasha and Stairs

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. 【codeforces 761B】Dasha and friends

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  3. 【codeforces 761C】Dasha and Password(动态规划做法)

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【codeforces 761C】Dasha and Password(贪心+枚举做法)

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【codeforces 761E】Dasha and Puzzle

    [题目链接]:http://codeforces.com/contest/761/problem/E [题意] 给你一棵树,让你在平面上选定n个坐标; 使得这棵树的连接关系以二维坐标的形式展现出来; ...

  6. 【Codeforces 459D】Pashmak and Parmida's problem

    [链接] 我是链接,点我呀:) [题意] 定义两个函数 f和g f(i)表示a[1..i]中等于a[i]的数字的个数 g(i)表示a[i..n]中等于a[i]的数字的个数 让你求出来(i,j) 这里i ...

  7. codeforces 761 D. Dasha and Very Difficult Problem(二分+贪心)

    题目链接:http://codeforces.com/contest/761/problem/D 题意:给出一个长度为n的a序列和p序列,求任意一个b序列使得c[i]=b[i]-a[i],使得c序列的 ...

  8. Codeforces 761D Dasha and Very Difficult Problem(贪心)

    题目链接 Dasha and Very Difficult Problem 求出ci的取值范围,按ci排名从小到大贪心即可. 需要注意的是,当当前的ci不满足在这个取值范围内的时候,判为无解. #in ...

  9. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

随机推荐

  1. [Vue CLI 3] 配置解析之 css.extract

    大家还记得我们在老版本中,对于线上环境配置中会把所有的 css 多打成一个文件: 核心是使用了插件 extract-text-webpack-plugin,方式如下: 第一步都是加载插件 const ...

  2. linux守护进程配置文件

    守护进程是一种运行在非交互模式下的程序.一般来说,守护进程任务是和联网区域有关的:它们等待连接,以便通过连接提供服务.Linux 可以使用从 Web 服务器到 ftp 服务器的很多守护进程. /etc ...

  3. JMeter与LoadRunner的对比

    1. 界面.安装.协议支持.函数库.成本.开源 2. 都可以实现分布式负载,相对来说LoadRunner更强大一些 3. 都支持在windows和linux环境的负载生成器.控制台方面,Jmeter跨 ...

  4. Leetcode771.Jewels and Stones宝石与石头

    给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头. S 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝石. J 中的字母不重复,J 和 S中的所有字符都是字母 ...

  5. 【NS2】用eclipse调试NS2(转载)

    相信很多喜欢Java的人对eclipse都情有独钟.NS2程序的调试,可以用打印命令调试,这样太繁琐.也可以用gdb调试,个人觉得上手比较困难.相信各位学习NS2的新手,在看代码的时候,很多的函数或者 ...

  6. svn总结 标签: svn开源软件 2015-05-09 17:31 513人阅读 评论(11) 收藏

    说到SVN,就不得不说CVS,CVS 是一个C/S系统,是一个常用的代码版本控制软件.主要在开源软件管理中使用.与它相类似的代码版本控制软件有subversion.多个开发人员通过一个中心版本控制系统 ...

  7. Java练习 SDUT-1586_计算组合数

    计算组合数 Time Limit: 1000 ms Memory Limit: 32768 KiB Problem Description 计算组合数.C(n,m),表示从n个数中选择m个的组合数. ...

  8. Python基础:05集合类型

    Python中,集合对象是一组无序排列的可哈希的值.所以集合成员可以做字典中的键.集合中的元素都是唯一的. 集合(sets)有两种不同的类型,可变集合(set) 和 不可变集合(frozenset). ...

  9. @codeforces - 1056G@ Take Metro

    目录 @description@ @solution@ @accepted code@ @details@ @description@ 环上有 n 个点,按顺时针顺序以 1 到 n 编号.其中 1~m ...

  10. PyTorch代码调试利器: 自动print每行代码的Tensor信息

    本文介绍一个用于 PyTorch 代码的实用工具 TorchSnooper.作者是TorchSnooper的作者,也是PyTorch开发者之一. GitHub 项目地址: https://github ...