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 ...
随机推荐
- docker重新安装后无法启动
问题描述: docker版本升级或者重新安装后,无法启动服务,出现如下报错: level=error msg="[graphdriver] prior storage driver over ...
- 解决 phpmyadmin #2002 无法登录 MySQL 服务器
将 “phpMyAdmin/libraries”文件夹下的config.default.php文件中的 $cfg['Servers'][$i]['host'] = 'localhost'; 修改为 $ ...
- 【两分钟视频教程】如何使用myeclipse在mac本机运行iOS配套的服务器
如何使用myeclipse在mac本机运行iOS配套的服务器
- HDU 2680 Choose the best route 最短路问题
题目描述:Kiki想去他的一个朋友家,他的朋友家包括所有的公交站点一共有n 个,一共有m条线路,线路都是单向的,然后Kiki可以在他附近的几个公交站乘车,求最短的路径长度是多少. 解题报告:这道题的特 ...
- MongoDB 之 $关键字 及 $修改器 $set $inc $push $pull $pop MongoDB - 4
我们在之前的 MongoDB 之 手把手教你增删改查 MongoDB - 2 中提到过 $set 这个系统关键字,用来修改值的对吧 但是MongoDB中类似这样的关键字有很多, $lt $gt $lt ...
- Coursera台大机器学习技法课程笔记10-Random forest
随机森林就是要将这我们之前学的两个算法进行结合:bagging能减少variance(通过g们投票),而decision tree的variance很大,资料不同,生成的树也不同. 为了得到不同的g, ...
- 前后端分离之mockjs基本介绍
安装与使用 # 安装 npm install mockjs #使用 Mock var Mock = require('mockjs') var data = Mock.mock({ // 属性 lis ...
- 安装Xampp-配置appche,mysql运行环境遇到的坑(转)
用php编写的web应用程序,需运行在php的web容器中,其中apache server是一个针对php web容器,它是apache下的开源项目.通常要运行一个web程序,我们还需要安装数据库软件 ...
- K8s中,tomcat的一部分jvm参数,如何通过env环境变量传递?
这两天解决的一个需求: 如果用户没有在deployment中设置env参数,则tomcat默认使用1G左右的内存: 如果用户在deployment中提供了jvm参数,则tomcat将这部分的参数,覆盖 ...
- List集合去除重复对象及equals()、hashCode()方法的作用
原文:https://blog.csdn.net/freelander_j/article/details/52211010 在java中,要将一个集合中重复的对象除去,如果这个集合中的数据类型是基本 ...