题目链接 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-2544最短路

    题目: 最短路 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  2. 16,Python网络爬虫之Scrapy框架(CrawlSpider)

    今日概要 CrawlSpider简介 CrawlSpider使用 基于CrawlSpider爬虫文件的创建 链接提取器 规则解析器 引入 提问:如果想要通过爬虫程序去爬取”糗百“全站数据新闻数据的话, ...

  3. Spring---浅谈AOP

    概念 AOP是Aspect Oriented Programming的缩写,即面向切面的编程.是一种比较新颖的编程思想,也是Spring框架中一个重要的领域. AOP将应用系统分为两个部分:核心业务逻 ...

  4. 电脑卡,eclipse Android stadio 卡,什么都卡解决方法

    昨天还好好的,今天什么都没有动就很卡.Android stadio 半天,改了东西才编译.什么都慢一拍,你能感觉到,打开网页也好,什么也好. 莫名的问题,总是被莫名的解决.真的,下了个360杀毒,没效 ...

  5. 某面试公司出的面试题---用JS比较两个版本号高低

    一天中午某个公司给我反馈的面试题,说,比较两个文件的版本号,然后我给发过去了,说我的代码不符合他的要求,o(╯□╰)o了var compareVersion = compareVersion||fun ...

  6. loj2043 「CQOI2016」K 远点对

    k-d tree 裸题------ #include <algorithm> #include <iostream> #include <cstdio> using ...

  7. Firewall Rule Properties Page: Advanced Tab

    Applies To: Windows 7, Windows Server 2008 R2 Use this tab to configure the profiles and interface t ...

  8. flex布局之flex-grow和flex-shrink如何计算

    此文已由作者张含会授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 关于盒模型布局 如何实现两栏布局? (表格) 流式, 浮动, 定位 如何选择? 流式 > 浮动 > ...

  9. Singleton模式类 【微软面试100题 第七十二题】

    题目要求: 实现C++单例模式,即只能生成一个实例的类. 题目分析: 1.一般情况:用构造函数私有化和静态函数实现. 2.如果考虑内存泄露:用智能指针+一般情况方法. 3.如果考虑线程安全:加锁. 代 ...

  10. Marketing learning-1

    Today we start to learn something about marketing together.Sometimes i just propose a question,and i ...