题目链接 Dasha and Very Difficult Problem

求出ci的取值范围,按ci排名从小到大贪心即可。

需要注意的是,当当前的ci不满足在这个取值范围内的时候,判为无解。

 #include <bits/stdc++.h>

 using namespace std;

 #define rep(i,a,b) for(int i(a); i <= (b); ++i)

 const int N =  + ;
int a[N], b[N], c[N], op[N];
int l, r, L, R, cnt;
bool flag;
int n, x; int main(){ scanf("%d%d%d", &n, &l, &r);
rep(i, , n) scanf("%d", a + i);
rep(i, , n) scanf("%d", c + i);
rep(i, , n) op[c[i]] = i; L = l - r, R = r - l; cnt = L; flag = true;
rep(i, , n){
x = op[i];
if (a[x] + cnt < l){
if (l - a[x] > cnt){
b[x] = l;
cnt = l - a[x] + ;
}
else{
flag = false;
break;
}
}
else
if (a[x] + cnt > r){
flag = false;
break;
}
else{
b[x] = a[x] + cnt;
++cnt;
}
} if (!flag) puts("-1");
else rep(i, , n) printf("%d ", b[i]);
return ; }

Codeforces 761D Dasha and Very Difficult Problem(贪心)的更多相关文章

  1. codeforces 761D - Dasha and Very Difficult Problem

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 【codeforces 761D】Dasha and Very Difficult Problem

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  6. 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序列的 ...

  7. 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]的相 ...

  8. Educational Codeforces Round 40 F. Runner's Problem

    Educational Codeforces Round 40 F. Runner's Problem 题意: 给一个$ 3 * m \(的矩阵,问从\)(2,1)$ 出发 走到 \((2,m)\) ...

  9. BNU 4356 ——A Simple But Difficult Problem——————【快速幂、模运算】

    A Simple But Difficult Problem Time Limit: 5000ms Memory Limit: 65536KB 64-bit integer IO format: %l ...

随机推荐

  1. HDU 3368 Reversi

    http://acm.hdu.edu.cn/showproblem.php?pid=3368 题意:模拟黑白棋,下一步黑手最大可以转化多少个白旗 分析:暴力 原先的思路是找到D然后遍历其八个方向,直到 ...

  2. 线段树[To be continued]

    目录 数据结构--线段树 一.定义 二.性质 三.基本操作 0.结构体 1.建树 2.单点查询 3.单点修改 4.区间修改 5.区间查询 四.题目 单点修改.区域查询模板 五.鸣谢 学姐的Blog 百 ...

  3. bootstrap button

    样式修改 .sign-button, .sign-button:hover, .sign-button:focus, .sign-button:active, .sign-button:visited ...

  4. 编写高性能React组件-传值篇

    很多人在写React组件的时候没有太在意React组件的性能,使得React做了很多不必要的render,现在我就说说该怎么来编写搞性能的React组件. 首先我们来看一下下面两个组件 import ...

  5. [oldboy-django][2深入django]学生管理(Form)--查看(分页)

    1 需求: 查看所有学生的信息,(分页功能) 2 前端:bootstrap美化前端 <!DOCTYPE html> <html lang="en"> < ...

  6. mysql环境变量配置(复制)

    前面步骤完成后安装好MySQL,为MySQL配置环境变量.MySQL默认安装在C:\Program Files下. 1)新建MYSQL_HOME变量,并配置:C:\Program Files\MySQ ...

  7. SEO相关

    前端需要注意哪些SEO 合理的title.description.keywords: -- 搜索对着三项的权重逐个减小,title值强调重点即可,重要关键词出现不要超过2次,而且要靠前,不同页面tit ...

  8. Ambari API 验证方式

    文章作者:luxianghao 文章来源:http://www.cnblogs.com/luxianghao/p/6123010.html  转载请注明,谢谢合作. 免责声明:文章内容仅代表个人观点, ...

  9. 【Luogu】P4462异或序列(莫队)

    题目链接 观察什么时候x到y之间那一段可以被统计 xorsum[x-1]^xorsum[y]=k xorsum[x-1]=xorsum[y]^k||xorsum[y]=xorsum[x-1]^k 莫队 ...

  10. [luogu3768] 简单的数学题 [杜教筛]

    题面: 传送门 实际上就是求: 思路: 看到gcd就先反演一下,过程大概是这样: 明显的一步反演 这里设,S(x)等于1到x的和 然后把枚举d再枚举T变成先枚举T再枚举其约数d,变形: 后面其中两项展 ...