B. Case of Fugitive

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/555/problem/B

Description

Andrewid the Android is a galaxy-famous detective. He is now chasing a criminal hiding on the planet Oxa-5, the planet almost fully covered with water.

The only dry land there is an archipelago of n narrow islands located in a row. For more comfort let's represent them as non-intersecting segments on a straight line: island i has coordinates [li, ri], besides, ri < li + 1 for 1 ≤ i ≤ n - 1.

To reach the goal, Andrewid needs to place a bridge between each pair of adjacent islands. A bridge of length a can be placed between the i-th and the (i + 1)-th islads, if there are such coordinates of x and y, that li ≤ x ≤ ri, li + 1 ≤ y ≤ ri + 1 and y - x = a.

The detective was supplied with m bridges, each bridge can be used at most once. Help him determine whether the bridges he got are enough to connect each pair of adjacent islands.

Input

The first line contains integers n (2 ≤ n ≤ 2·105) and m (1 ≤ m ≤ 2·105) — the number of islands and bridges.

Next n lines each contain two integers li and ri (1 ≤ li ≤ ri ≤ 1018) — the coordinates of the island endpoints.

The last line contains m integer numbers a1, a2, ..., am (1 ≤ ai ≤ 1018) — the lengths of the bridges that Andrewid got.

Output

If it is impossible to place a bridge between each pair of adjacent islands in the required manner, print on a single line "No" (without the quotes), otherwise print in the first line "Yes" (without the quotes), and in the second line print n - 1 numbers b1, b2, ..., bn - 1, which mean that between islands i and i + 1 there must be used a bridge number bi.

If there are multiple correct answers, print any of them. Note that in this problem it is necessary to print "Yes" and "No" in correct case.

Sample Input

4 4
1 4
7 8
9 10
12 14
4 5 3 8

Sample Output

Yes
2 3 1

HINT

题意

有一排岛,然后让你在m个桥中选n个,然后搭在这些岛上,让相邻的岛相连接,输出方案

题解:

一开始脑补的是跑最大流,然后想了想复杂度,还是贪心搞吧

先把每个桥可以搭的区间找出来,然后排序,找到小于右端点的最大值

然后就好了

其中输出编号比较麻烦,我们pair就好了

代码

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef unsigned long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 2000001
#define mod 1000000007
#define eps 1e-9
int Num;
char CH[20];
const int inf=0x3f3f3f3f;
inline ll read()
{int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;
}//**************************************************************************************set<pair<ll,int> >s;
pair<pair<ll,ll>,int> br[maxn];
pair<ll,ll> a[maxn];
set<pair<ll,int> >::iterator it;
int ans[maxn];
int main()
{int n=read(),m=read();for(int i=0;i<n;i++)cin>>a[i].first>>a[i].second;for(int i=0;i<n-1;i++)br[i]=make_pair(make_pair(a[i].second-a[i+1].first,a[i].first-a[i+1].second),i);for(int i=0;i<m;i++){ll kiss;cin>>kiss;s.insert(make_pair(kiss,i));}sort(br,br+n-1);for(int i=0;i<n-1;i++){ll l=-br[i].first.first,r=-br[i].first.second;it=s.lower_bound(make_pair(r,inf));if(it==s.begin())return puts("No");it--;if(it->first<l)return puts("No");ans[br[i].second]=it->second;s.erase(it);}puts("Yes");for(int i=0;i<n-1;i++)cout<<ans[i]+1<<" ";
}

转载于:https://www.cnblogs.com/qscqesze/p/4604999.html

Codeforces Round #310 (Div. 1) B. Case of Fugitive set相关推荐

  1. Codeforces Round #604 (Div.2)

    Codeforces Round #604 (Div.2) 2019/12/5 22:35--2019/12/6 00:35 Codeforces Round #604 (Div.2) A. Beau ...

  2. Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #696 (Div. 2) (A ~ E)超高质量题解 比赛链接:h ...

  3. Codeforces Round #698 (Div. 2)(A ~ F)6题全,超高质量题解)【每日亿题】2021/2/4

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 [每日亿题]Codeforces Round #698 (Div. 2)(A ~ F)6题全,超 ...

  4. Codeforces Round #648 (Div. 2)(A, B, C, D)

    Codeforces Round #648 (Div. 2) 或许更好的阅读体验 A:Matrix Game 思路 题意可以说是非常简单的,我们选定的格子的行列都不能存在1,可以发现我们可以放的格子一 ...

  5. Codeforces Round #538 (Div. 2) F. Please, another Queries on Array? 线段树 + 欧拉函数

    传送门 文章目录 题意: 思路: 题意: 给你一个序列aaa,你需要实现两种操作: (1)(1)(1) 将[l,r][l,r][l,r]的aia_iai​都乘rrr. (2)(2)(2) 求ϕ(∏i= ...

  6. Codeforces Round #620 (Div. 2)(D. Shortest and Longest LIS)(O(n log n)的最长上升子序列或者贪心)

    Codeforces Round #620 (Div. 2)(D. Shortest and Longest LIS)(O(n log n)的最长上升子序列或者贪心) time limit per t ...

  7. Codeforces Round #644 (Div. 3) E.Polygon

    Codeforces Round #644 (Div. 3) E.Polygon 题目链接 Polygon is not only the best platform for developing p ...

  8. Codeforces Round #644 (Div. 3) D.Buying Shovels

    Codeforces Round #644 (Div. 3) D.Buying Shovels 题目链接 Polycarp wants to buy exactly n shovels. The sh ...

  9. Codeforces Round #644 (Div. 3) F.Spy-string

    Codeforces Round #644 (Div. 3) F.Spy-string 题目链接 You are given n strings a1,a2,-,an: all of them hav ...

最新文章

  1. C#.Net 如何动态加载与卸载程序集(.dll或者.exe)6-----在不卸载程序域的前提下替换程序集文件。...
  2. [文摘20090224]天干和地支
  3. iOS如何在iTunes网站查看并下载APP的dsym文件
  4. java springboot 搭建_springboot搭建java项目
  5. python修改html的td_python3修改HTMLTestRunner,生成有截图的测试报告,并发送测试邮件(一)...
  6. (转)MySQL索引原理及慢查询优化
  7. springboot出现Requested bean is currently in creation: Is there an unresolvable circular reference?
  8. 20140904 atoi字符串转化为整数源码
  9. 'django_tables2' is not a registered tag library. Must be one of:
  10. [导入]C#面向对象设计模式纵横谈(10):Decorator 装饰模式(结构型模式).zip(9.84 MB)...
  11. EndNote使用技巧之一--参考文献的导入
  12. Qt4_与主线程通信
  13. 火线精英显示服务器一断,火线精英bug大全解析
  14. Linux下新手基本操作及技巧看图上路
  15. 企业微信发送信息异常的临时处理方案
  16. dp hdu5653 xiaoxin and his watermelon candy
  17. 如何把地址导航生成二维码?
  18. Unity实战之见缝插针
  19. MySQL密码修改不成功_Mysql 修改密码不成功(不生效)的解决办法
  20. Java 中String构造方法

热门文章

  1. 合并数字 — m个数字消除相邻的差的绝对值为1的两个数中较大的那一个,直到没有两个相邻的差的绝对值为 1 的数(动态数组定义)
  2. bzoj 3111: [Zjoi2013]蚂蚁寻路(DP)
  3. 类别不平衡问题之评估指标
  4. 自动化运维工具(ansible入门教程)
  5. pmod ad2 digilent 提供的pmodad2.c和pmodad2.h
  6. 串的复制——串传送指令MOVSB和方向标志位DF和CLD和REP
  7. 荣耀10 原版android,荣耀V10新内置壁纸
  8. 欧几里得求最大公约数--JAVA递归实现
  9. Java8 改进的匿名内部类:
  10. golang 安装 guru vscode 安装失败