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
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.
Sample Input
5 1 5
1 1 1 1 1
3 1 5 4 2
Sample Output
3 1 5 4 2
Hint
题意
c[i]=b[i]-a[i],现在给你a[i]和c[i]的相对大小,问你可不可能出现b[i]满足条件,如果有的话,输出。
题解:
贪心,最小的显然要最小,次小的在比最小大的基础上最小就好了。
对于每一个数都二分一下就完了。
代码
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
long long l,r,a[maxn],b[maxn],c[maxn];
priority_queue<pair<int,int> >S;
int n,op[maxn];
int main()
{
scanf("%d%lld%lld",&n,&l,&r);
for(int i=0;i<n;i++){
scanf("%lld",&a[i]);
}
for(int i=0;i<n;i++)
scanf("%d",&op[i]),S.push(make_pair(op[i],i));
long long last = -1e16;
while(!S.empty()){
long long now = S.top().second;
S.pop();
long long L=l,R=r,Ans=r+1;
while(L<=R){
long long mid=(L+R)/2;
if(a[now]-mid>last){
L=mid+1,Ans=mid;
}else
R=mid-1;
}
if(Ans==r+1){
cout<<"-1"<<endl;
return 0;
}
b[now]=Ans;
last=a[now]-Ans;
}
for(int i=0;i<n;i++)
cout<<b[i]<<" ";
cout<<endl;
}
Codeforces Round #394 (Div. 2) D. Dasha and Very Difficult Problem 贪心的更多相关文章
- 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) D. Dasha and Very Difficult Problem
D. Dasha and Very Difficult Problem time limit per test:2 seconds memory limit per test:256 megabyte ...
- 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 ...
随机推荐
- [iOS]Xcode+GitHub远程代码托管(GIT, SVN)
先来看看什么是代码远程托管: 其实就是将我们的代码上传到GitHub的服务器上, 供别人下载, 当然了也可以在团队开发的时候, 使用GitHub进行代码合并工作, 下面我们进入正题 (已经有远程仓库的 ...
- git 学习小记之记住https方式推送密码
昨天刚刚学了点git基础操作,但是不幸的是Git@OSC给出公告说尽量使用 https 进行操作.可是在用 https 进行 push 时,都需要输入帐号和密码. 各种百度谷歌之后在Git@OSC官网 ...
- 【问题收集·中级】关于XMPP使用Base传送图片
[问题收集·中级]关于XMPP使用Base传送图片 下面是我与博友的问答过程:并在最后链接附录了相应的文件: 博友问题: 16:35:38 他跟我说要 内容图片 base64编码 上传..博友问题 ...
- python中的__getattr__、__getattribute__、__setattr__、__delattr__、__dir__
__getattr__: 属性查找失败后,解释器会调用 __getattr__ 方法. class TmpTest: def __init__(self): self.tmp = 'tmp12 ...
- NOI2001 方程的解数(双向搜索)
solution 一道非常经典的双向搜索题目,先将前3个未知数枚举一遍得到方程的前半部分所有可能的值,取负存入第一个队列中再将后3个未知数枚举一遍,存入第二个队列中.这样我们只要匹配两个队列中相同的元 ...
- 洛谷 P1006 传纸条 多维DP
传纸条详解: 蒟蒻最近接到了练习DP的通知,于是跑来试炼场看看:发现有点难(毕竟是蒟蒻吗)便去翻了翻题解,可怎么都看不懂.为什么呢?蒟蒻发现题解里都非常详细的讲了转移方程,讲了降维优化,但这题新颖之处 ...
- 【SVN】命令行忽略不必要的文件和文件夹
SVN命令参考: https://www.cnblogs.com/wlsxmhz/p/5775393.html 我们需要明白命令行设置忽略文件和文件夹是通过设置svn:ignore属性设置的,pr ...
- 【ARTS】01_06_左耳听风-20181217~1223
ARTS: Algrothm: leetcode算法题目 Review: 阅读并且点评一篇英文技术文章 Tip/Techni: 学习一个技术技巧 Share: 分享一篇有观点和思考的技术文章 Algo ...
- Webservice soap wsdl区别之个人见解
原文:http://blog.csdn.net/pautcher_0/article/details/6798351 Web Service实现业务诉求:Web Service是真正“办事”的那个,提 ...
- NET调用Com组件事例
http://blog.csdn.net/shizhiyingnj/article/details/1507948 在程序设计中,往往通过键盘的某个按键来完成相关操作! 下面就来说明如何实现: 1.引 ...