Codeforces Round #394 (Div. 2) D. Dasha and Very Difficult Problem
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 sequencec = [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.
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.
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.
- 5 1 5
1 1 1 1 1
3 1 5 4 2
- 3 1 5 4 2
- 4 2 9
3 4 8 9
3 2 1 4
- 2 2 2 9
- 6 1 5
1 1 1 1 1 1
2 3 5 4 1 6
- -1
Sequence b which was found in the second sample is suitable, because calculated sequencec = [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].
题意:
给你序列p和序列a,让你找一个合法的序列b,输出。
序列c是通过bi-ai来得到的。
序列p是通过离散化序列c来得到的。(离散化c序列,就是将c序列中的数字从小到大编号)
- #include <iostream>
- #include<cstdio>
- #include<algorithm>
- using namespace std;
- struct node
- {
- int id,num;
- }a[];
- int b[],k[];
- int n,l,r;
- bool cmp(node a,node b)
- {
- return a.id>b.id;
- }
- int main()
- {
- scanf("%d%d%d",&n,&l,&r);
- for(int i=;i<=n;i++) scanf("%d",&a[i].num);
- for(int i=;i<=n;i++) {scanf("%d",&a[i].id); k[i]=a[i].id;}
- sort(a+,a+n+,cmp);
- b[]=r;
- bool flag=;
- for(int i=;i<=n;i++)
- {
- /*
- if (b[i-1]-a[i-1].num-1+a[i].num<l ||
- b[i-1]-a[i-1].num-1+a[i].num>r)
- {
- flag=0;
- break;
- }
- b[i]=b[i-1]-a[i-1].num-1+a[i].num;
- //以上是错误的,只考虑了差是连续,若是不连续没考虑。
- */
- if (b[i-]-a[i-].num-+a[i].num>=l)
- {
- b[i]=b[i-]-a[i-].num-+a[i].num;
- if (b[i]>r) b[i]=r; //使差减小得更多。
- }
- else { flag=; break; }
- }
- if (!flag) printf("-1");
- else{
- for(int i=;i<=n;i++)
- {
- if (i-) printf(" ");
- printf("%d",b[n-k[i]+]);
- }
- }
- printf("\n");
- return ;
- }
Codeforces Round #394 (Div. 2) D. Dasha and Very Difficult Problem的更多相关文章
- 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 ...
- 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 ...
- Codeforces Round #394 (Div. 2) E. Dasha and Puzzle(分形)
E. Dasha and Puzzle time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- Codeforces Round #394 (Div. 2) E. Dasha and Puzzle 构造
E. Dasha and Puzzle 题目连接: http://codeforces.com/contest/761/problem/E Description Dasha decided to h ...
- Codeforces Round #394 (Div. 2) C. Dasha and Password 暴力
C. Dasha and Password 题目连接: http://codeforces.com/contest/761/problem/C Description After overcoming ...
- Codeforces Round #394 (Div. 2) B. Dasha and friends 暴力
B. Dasha and friends 题目连接: http://codeforces.com/contest/761/problem/B Description Running with barr ...
- Codeforces Round #394 (Div. 2) A. Dasha and Stairs 水题
A. Dasha and Stairs 题目连接: http://codeforces.com/contest/761/problem/A Description On her way to prog ...
- Codeforces Round #394 (Div. 2) C. Dasha and Password —— 枚举
题目链接:http://codeforces.com/problemset/problem/761/C C. Dasha and Password time limit per test 2 seco ...
- Codeforces Round #394 (Div. 2) B. Dasha and friends —— 暴力 or 最小表示法
题目链接:http://codeforces.com/contest/761/problem/B B. Dasha and friends time limit per test 2 seconds ...
随机推荐
- Linux上free命令的输出及其他
一.明确概念 A buffer is something that has yet to be "written" to disk. A cache is something t ...
- hadoop namenode
存储文件系统元数据,例如:文件目录结构,不同文件的分块情况,每块存储在那个节点,权限等 这些元数据全部存储在内存中,所以,namenode要求内存比较大 hdfs在存文件的时候会按照块存储,每一块默认 ...
- (4.6)sql2008中的group by grouping sets
最近遇到一个情况,需要在内网系统中出一个统计报表.需要根据不同条件使用多个group by语句.需要将所有聚合的数据进行UNION操作来完成不同维度的统计查看. 直到发现在SQL SERVER 200 ...
- 【Myeclipse设置】MyEclipse取消Show in Breadcrumb的方法
有时不小心把快捷导航整出来,对于本来就很小的编辑空间来讲就很痛苦了,下面的方法可行,本人亲自试验过. 参考地址:百度文库中的解决方法 在最后用户通过点击出来的图标 ,就可以自如的控制出现和消失了.
- Linux开发工具教程
今天把上个星期写的Linux开发工具相关的教程整理一下,方便阅读: 1.第一课 GCC入门: 2.第二课 GCC入门之静态库以及共享库: 3.第三课 Makefile文件的制作(上) : 4.第四课 ...
- 113. Path Sum II(求等于某个数的所有路径)
Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the given su ...
- dogo 官方翻译 Ajax with dojo/request
require(["dojo/request"], function(request){ request("helloworld.txt").then( fun ...
- 【Java Web】新手教程(转)
转自:http://www.journaldev.com/1854/java-web-application-tutorial-for-beginners#web-server-client Web ...
- python中访问限制
在Class内部,可以有属性和方法,而外部代码可以通过直接调用实例变量的方法来操作数据,这样,就隐藏了内部的复杂逻辑. 但是,从前面Student类的定义来看,外部代码还是可以自由地修改一个实例的na ...
- JMeter并发性测试
JMeter并发性测试 一.JMeter简介 JMeter是apache公司基于java开发的一款开源压力测试工具,体积小,功能全,使用方便,是一个比较轻量级的测试工具,使用起来非常简单.因为jmet ...