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 ...
随机推荐
- phpStorm 8.0.3 设置
phpstorm 8 license key Learn Programming===== LICENSE BEGIN =====63758-1204201000000Ryqh0NCC73lpRm!X ...
- HTML5 移动开发(移动设备检测及对HTML5的支持)
1.如何选择要使用的特性以及所面向的浏览器 2.哪些浏览器支持HTML5 3.如何检测是否支持HTML5 4.如何开发贷容错性的Web应用程序 5.CSS3媒体查询如何增强检测脚本 使用HTML5 ...
- 第7月第17天 rxswift swift3.0
1.rxswift just(...) .subscribe(onNext: { }) https://realm.io/cn/news/slug-max-alexander-functional-r ...
- python垃圾回收二
由于循环引用的存在,我们在删除了a跟b之后,引用计数是1,这样,现有的垃圾回收机制是永远不可能把她们删除了.他们将永远存在于内存中. 我们当然不能对这种情况置之不理,于是,我们又添加了两种新的回收机制 ...
- 如何使用jpegtran 压缩JPG图片
说到jpegtran相信很多人都比较陌生,网上相关的资料也很少. jpegtran可以让图片更加的简化,缩小图片的容量,从而增加网络的传输速度.说在多你也不信,下面就让事实证明. 首先下载 jpeg ...
- Linux进程托管与守护进程设置
引言 在上一篇<Linux启动之旅>中,我们了解了Linux启动过程,在该过程的最后一步,init进程拉起/etc/init.d/rcN.d/目录下指定的守护进程(daemon).假若自定 ...
- linux,mac安装sentry
linux,mac安装sentry 最近需要一个日志监视系统所以选择了sentry.以下是用mac安装,看需求量linux安装类似后面的文章会补充. 安装docker https://download ...
- MySQL安装与初步操作
MySQL是一款出色的中小型关系数据库,做Java Web开发时,要做到数据持久化存储,选择一款数据库软件自然必不可少. 由于MySQL社区版开元免费,功能比较强大,在此以MySQL为例,演示MySQ ...
- ASP .Net Core系统部署到SUSE Linux Enterprise Server 12 SP3 64 具体方案
.Net Core 部署到 SUSE Linux Enterprise Server 12 SP3 64 位中的步骤 1.安装工具 1.apache 2..Net Core(dotnet-sdk-2. ...
- R语言学习笔记:使用tcltk包显示进度条
一般在跑耗时较长的程序时,我们不知道程序到底有没有正常跑着,或者在爬虫的时候不知道爬到什么时候断了.因此可以添加进度条来显示当前进度,观察进度是否有进展.当进度条卡住的时候,可以判断程序断线,从而可以 ...