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序列的大小顺序和p序列一样。
p序列给出的的是1~n不重复的数。还有给出的l和r是b序列的大小范围
显然为了要使结果存在尽量使b取得最接近r,所以可以先按p排序一下,从大到小处理b,二分l,r的值使得每次的b尽量
大。
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int M = 1e5 + 10;
int a[M] , p[M] , b[M];
struct TnT {
int A , P , num;
}T[M];
bool cmp(TnT x , TnT y) {
return x.P > y.P;
}
int binsearch(int l , int r , int num , int now) {
int mid = (l + r) >> 1;
while(l <= r) {
mid = (l + r) >> 1;
if(mid - now >= num) {
r = mid - 1;
}
else {
l = mid + 1;
}
}
return r;
}
int main() {
int n , l , r;
cin >> n >> l >> r;
for(int i = 0 ; i < n ; i++) {
cin >> a[i];
}
for(int i = 0 ; i < n ; i++) {
cin >> p[i];
T[i].A = a[i] , T[i].P = p[i] , T[i].num = i;
}
sort(T , T + n , cmp);
int flag = 0; for(int i = 0 ; i < n ; i++) {
if(i == 0) {
b[T[i].num] = r;
}
else {
int gg = b[T[i - 1].num] - a[T[i - 1].num];
int pos = binsearch(l , r , gg , a[T[i].num]);
if(pos == l - 1) {
flag = 1;
break;
}
b[T[i].num] = pos;
}
}
if(flag) {
cout << - 1 << endl;
}
else {
for(int i = 0 ; i < n ; i++) {
cout << b[i] << ' ';
}
cout << endl;
}
return 0;
}
codeforces 761 D. Dasha and Very Difficult Problem(二分+贪心)的更多相关文章
- 【codeforces 761D】Dasha and Very Difficult Problem
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 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]的相 ...
- 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) 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 761D Dasha and Very Difficult Problem(贪心)
题目链接 Dasha and Very Difficult Problem 求出ci的取值范围,按ci排名从小到大贪心即可. 需要注意的是,当当前的ci不满足在这个取值范围内的时候,判为无解. #in ...
- codeforces 761D - Dasha and Very Difficult Problem
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- codeforces 761 C. Dasha and Password(多维dp)
题目链接:http://codeforces.com/contest/761/problem/C 题意:给出n行的字符串每一列都从第一个元素开始可以左右移动每一行字符串都是首位相连的. 最后问最少移动 ...
- Codeforces Round #253 Div2 D.Andrey and Problem 概率+贪心
概率计算:P(某set) = 令: 和 现在考虑: 1.考虑某个集合,再加一个概率为Pi的朋友后能不能使总概率提高. 即: 由公式可知, 如果 S < 1,则delta > 0,则 ...
随机推荐
- AUTOSAR学习之RTE - 基本概念
1.什么是RTE? The Run-Time Environment (RTE) is at the heart of the AUTOSAR ECU architecture. The RTE is ...
- java基础精选题
Integer比较 看下面这段有意思的代码,对数字比较敏感的小伙伴有没有发现异常? public static void main(String[] args) { Integer a = 128,b ...
- Oracle 存储过程批量插入数据
oracle 存储过程批量插入大量数据 declare numCount number; userName varchar2(512); email varchar2(512); markCommen ...
- 七天学会NodeJS——第一天
转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者.原文出处:http://nqdeng.github.io/7-days-nodejs Node.js 是一个能 ...
- [NUnit]No results
Results (nunit3) saved as TestResult.xmlCommitting...No results, this could be for a number of reaso ...
- hadoop安装解决之道
# 壹.故障现象 ```xml Microsoft Windows [版本 10.0.18362.239] (c) 2019 Microsoft Corporation.保留所有权利. C:\User ...
- 浅谈 JavaScript 垃圾回收机制
github 获取更多资源 https://github.com/ChenMingK/WebKnowledges-Notes 在线阅读:https://www.kancloud.cn/chenmk/w ...
- 洛谷 P4344 [SHOI2015]脑洞治疗仪
题意简述 维护序列,支持以下操作: 0 l r:将l~r赋为0 1 l1 r1 l2 r2:将l1~r1中的1替换l2~r2中的0,多余舍弃 2 l r:询问l~r中最大连续1的长度 题解思路 珂朵莉 ...
- 在linux中部署项目并创建shell脚本
1.首先要在idea中父工程maven包下执行clean生成的target包 2.执行package打包,打包时候讲test勾去掉 3.将target包中生成的jar包cp出来 此处注意打包时必须要保 ...
- 第 10 篇:小细节 Markdown 文章自动生成目录,提升阅读体验
目录 在文中插入目录 在页面的任何地方插入目录 处理空目录 美化标题的锚点 URL 作者:HelloGitHub-追梦人物 文中涉及的示例代码,已同步更新到 HelloGitHub-Team 仓库 上 ...