题目链接 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. 笔记-编程-IO模型

    笔记-编程-IO模型 1.      简介 常用IO模型 1)      同步阻塞IO(Blocking IO) 2)      同步非阻塞IO(Non-blocking IO) 3)      IO ...

  2. 使用HTTP协议访问网路

    使用HTTP协议访问网路 一.使用HttpURLConnection //new一个URL对象 URL url = new URL("http://www.qq.com");//千 ...

  3. SparkStreaming和Kafka的整合

    当我们正确地部署好Spark Streaming,我们就可以使用Spark Streaming提供的零数据丢失机制.需要满足以下几个先决条件: 1.输入的数据来自可靠的数据源和可靠的接收器: 2.应用 ...

  4. springboot学习资料汇总

    收集Spring Boot相关的学习资料,Spring Cloud点这里 推荐博客 纯洁的微笑 程序猿DD liaokailin的专栏 Spring Boot 揭秘与实战 系列 catoop的专栏 简 ...

  5. SQL调优--记一次表统计信息未及时更新导致查询超级慢

                某日同事丢给我一个看上去复杂的查询(实际就涉及两张表,套来套去)说只是换了日期条件,但一个查询5秒出数据,一个根本查不出来.现在整理下解决过程,及涉及的知识点. 若有不正之处, ...

  6. luogu3810 【模板】三维偏序(陌上花开)

    ref1 ref2 ref3 ref4 #include <algorithm> #include <iostream> #include <cstdio> usi ...

  7. jmeter正则表达式提取 引用

    jmeter正则表达式token提取 例: 添加正则 配置 token正则表达式:"token":"(.+?)" 模板:$1$ 添加信息头管理器进行配置 需要t ...

  8. Leetcode 632.最小区间

    最小区间 你有 k 个升序排列的整数数组.找到一个最小区间,使得 k 个列表中的每个列表至少有一个数包含在其中. 我们定义如果 b-a < d-c 或者在 b-a == d-c 时 a < ...

  9. DataFrame的iloc与loc的区别是什么?

    对于一个DataFrame A,A.loc[k]是读取A中index为k的那一行.A.iloc[k]是读取A中的第k行.

  10. vmware安装centos7 安装redis windows7访问redis

    1.在windows7中安装vmware 2.在vmware中安装centos7 3.禁用centos7自带的firewalld.service 4.安装iptables防火墙 5.安装Redis 3 ...