题目链接 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. Patrick and Shopping

    Patrick and Shopping 今天 Patrick 等待着他的朋友 Spongebob 来他家玩.为了迎接 Spongebob,Patrick 需要去他家附近的两家商店  买一些吃的.他家 ...

  2. Android 服务入门

    前言:硬着头皮把数据库SQLite看完了,接下来就是android服务了,因为自己本身就是菜鸟,所以呢,也只是做做笔记,技术上的东西就别指望我了. 1.什么是服务呢?举个例子,百度地图,美团外卖,OF ...

  3. JDK各版本新特性浅谈

    JDK 5.0 自动拆装箱 枚举 可变参数 泛型 For -each 内省 静态导入 JDK 6.0 console开发控制台程序 轻量级HTTP ServerAPI 支持脚本语言 使用Compile ...

  4. Spring---浅谈IOC

    概念 IOC(Inversion of Control 控制反转)是spring的核心,贯穿始终.所谓IOC,对于spring框架来说,就是由spring来负责控制对象的生命周期和对象间的关系. 传统 ...

  5. Redis实现之对象(二)

    列表对象 列表对象的编码可以是ziplist或者linkedlist,ziplist编码的列表对象使用压缩列表作为底层实现,每个压缩列表节点(entry)保存了一个列表元素.举个栗子,如果我们执行RP ...

  6. day 16 JS DOM 继续

    为什么有jquey了还学DOM  ? 因为JQuey 是大而全,可能有10k 但是我们用到的只有1k  网站小没事,网站大流量就是问题 所以大网站都是自己用DOM 实现一个类似于JQuey 的适合自己 ...

  7. xcode6没有prefix.pch预编译文件解决办法

    注意到Xcode6创建的工程没有prefix.pch. 于是手动创建. 在other下选择pch文件 接着到工程的build setting下设置开启预编译并配置路径(文件的路径.因为我新建在cofi ...

  8. 【Clone Graph】cpp

    题目: Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. ...

  9. log4j2异步日志配置及官方文档的问题澄清

    配置及demo 方法一全部打开 加启动参数 -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextS ...

  10. POJ 2217:Secretary(后缀数组)

    题目大意:求两个字符串的公共子串. 分析: 模板题,将两个字符串接起来用不会出现的字符分割,然后求分属两个字符串的相邻后缀lcp的最大值即可. 代码: program work; type arr=. ...