time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard 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 nlr (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

给一个数列a,给一个数列p,已知数列p是数列c按个元素大小编号1~n后的所谓的压缩数列,求任意一个符合条件的数列b=a+c(条件:数列a、b都在某个范围内);

思路:

例如对于第二组样例,

3 4 8 9

根据 3 2 1 4的大小重排后得到

8 4 3 9 (a)

1 2 3 4 (p)

相对应的,不妨假设数列b对应的第一位为下界2,那么可知数列c的对应第一位为-6

8 4 3 9 (a)

1 2 3 4 (p)

-6          (c)

2           (b)

再看第二位,不妨假设b还是下界,则c为-2,-2 > -6,符合p给定的大小顺序,则可以有:

8 4 3 9 (a)

1 2 3 4 (p)

-6 -2        (c)

2  2      (b)

再到第三位,不妨设b还是下界,则c为-1,依然符合p的大小顺序

8  4  3  9 (a)

1  2  3  4 (p)

-6 -2 -1     (c)

2  2  2     (b)

再到第四位,设b为下界,则c为-7,这时候发现不符合顺序,那么就让c等于前一位+1

8   4   3   9  (a)

1   2   3   4  (p)

-6  -2  -1  0  (c)

2   2   2   9   (b)

这时候,得到的b为9,不大于上界,符合条件,因此我们得到了一个符合条件的b:

2   2   2   9   (b)

最后我们在将数列b排回3 2 1 4的顺序即可(这步很重要……在这个样例里重新排序之后没有变化,但其他样例就不一定了……)

3   2   1   4  (p)

2   2   2   9   (b)

感觉自己写的代码一点都不优雅……(羞耻……

 #include<cstdio>
int main()
{
int n,l,r,a[+],temp_a[+],p[+],c[+];
scanf("%d %d %d",&n,&l,&r);
for(int i=;i<=n;i++) scanf("%d",&temp_a[i]);
for(int i=;i<=n;i++) scanf("%d",&p[i]);
for(int i=;i<=n;i++) a[ p[i] ]=temp_a[i]; //for(int i=1;i<=n;i++) printf("%d ",a[i]);printf("\n"); int now=l-a[]-;
for(int i=;i<=n;i++)
{
if(l-a[i] > now) c[i]=(now=l-a[i]);
else c[i]=(now+=);
if( c[i]+a[i] > r ){
printf("-1\n");
return ;
}
} for(int i=;i<=n;i++){
if(i!=) printf(" ");
printf("%d",c[p[i]]+a[p[i]]);
}
printf("\n");
return ;
}

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

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

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

  2. Codeforces Round #394 (Div. 2) D. Dasha and Very Difficult Problem 贪心

    D. Dasha and Very Difficult Problem 题目连接: http://codeforces.com/contest/761/problem/D Description Da ...

  3. Codeforces Round #394 (Div. 2) D. Dasha and Very Difficult Problem —— 贪心

    题目链接:http://codeforces.com/contest/761/problem/D D. Dasha and Very Difficult Problem time limit per ...

  4. Codeforces Round #394 (Div. 2) D. Dasha and Very Difficult Problem

    D. Dasha and Very Difficult Problem time limit per test:2 seconds memory limit per test:256 megabyte ...

  5. 【codeforces 761D】Dasha and Very Difficult Problem

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

  6. 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序列的 ...

  7. D. Dasha and Very Difficult Problem 二分

    http://codeforces.com/contest/761/problem/D c[i] = b[i] - a[i],而且b[]和a[]都属于[L, R] 现在给出a[i]原数组和c[i]的相 ...

  8. Educational Codeforces Round 40 F. Runner's Problem

    Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...

  9. BNU 4356 ——A Simple But Difficult Problem——————【快速幂、模运算】

    A Simple But Difficult Problem Time Limit: 5000ms Memory Limit: 65536KB 64-bit integer IO format: %l ...

随机推荐

  1. c#直接调用ssis包实现Sql Server的数据导入功能

    调用ssis包实现Sql Server的数据导入功能网上已经有很多人讨论过,自己参考后也动手实现了一下,上一次笔者的项目中还用了一下这个功能.思前想后,决定还是贴一下增强记忆,高手请54. 1.直接调 ...

  2. Git Step by Step – (1) Git 简介

    由于工作的需要,代码版本控制工具要从Perforce换成Git.说实话,刚开始真的很不适应,要从一个可以很好的支持用户界面的工具转到一个命令行工具,而且Git中有几百个命令,一下子就傻眼了. 但是经过 ...

  3. 一张图了解SSH端口转发

    ssh和端口转发什么的,我就不想废话了,主要是ssh的命令格式真心不太好理解.网上也搜过相关文章,参差不齐.其实自己也理解怎么用,但我自己也表达不好.这几日无意碰到篇好文章,有图有真相,清楚的很,还有 ...

  4. 【ArcGIS】WebAdaptorIIS 安装前准备及配置Portal For ArcGIS的问题解决

    1.计算机全名配置 2.IIS-服务器证书配置 3.端口绑定 备注:配置Portal For ArcGIS总会提示计算机域名.全名错误.完全限定域名,可能就是没有进行第一步操作 4.Portal目录

  5. 【代码审计】CLTPHP_v5.5.3前台XML外部实体注入漏洞分析

    0x01 环境准备 CLTPHP官网:http://www.cltphp.com 网站源码版本:CLTPHP内容管理系统5.5.3版本 程序源码下载:https://gitee.com/chichu/ ...

  6. PHP代码审计笔记--文件包含漏洞

    有限制的本地文件包含: <?php include($_GET['file'].".php"); ?> %00截断: ?file=C://Windows//win.in ...

  7. Ansible的Inventory管理

    Ansible将可管理的服务器集合成为Inventory,Inventory的管理便是服务器的管理. hosts文件的位置: /etc/ansible/hosts 在命令行通过-i参数指定 通过/et ...

  8. LINUX安装中文输入法和那些大坑

    明明有很多事要做,却偏偏不知道要做什么,这种感觉,很令人上火. 一.基础知识 在原生ubuntu14.04英文环境系统中只有IBus拼音,真的好难用.由于搜狗输入法确实比Linux系统下其它的中文输入 ...

  9. hadoop集群操作常用命令

    一.HDFS相关 1.启动NameNode sbin/hadoop-daemon.sh start namenode 2.启动DataNode sbin/hadoop-<span style=& ...

  10. no matching function for call to ‘std::basic_string<char>::assign(std::string&, int)

    使用string中的assign赋值函数报错,代码为: text0.assign(line,i+); 其中text0与line都为string类型 最后发现assign函数的原型为 string &a ...