Case of Fugitive

CodeForces - 555B

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 adjacentislands. 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 ≤ rili + 1 ≤ y ≤ ri + 1and 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 - 1numbers 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.

Examples

Input
4 4
1 4
7 8
9 10
12 14
4 5 3 8
Output
Yes
2 3 1
Input
2 2
11 14
17 18
2 9
Output
No
Input
2 1
1 1
1000000000000000000 1000000000000000000
999999999999999999
Output
Yes
1

Note

In the first sample test you can, for example, place the second bridge between points 3 and 8, place the third bridge between points 7 and 10 and place the first bridge between points 10 and 14.

In the second sample test the first bridge is too short and the second bridge is too long, so the solution doesn't exist.

sol:把桥按照长度从小到大排序,对于每两座岛之间的桥长是一个闭区间[L,R]

对于桥一个个枚举过去,如当前桥长是a,对于所有L<=a的找到R最小的那个,贪心一遍即可

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,m;
ll Daol[N],Daor[N];
struct Juli
{
ll Down,Up,Id;
inline bool operator<(const Juli &tmp)const
{
return Up>tmp.Up;
}
}Dis[N];
inline bool cmp_Juli(Juli p,Juli q)
{
return p.Down<q.Down;
}
priority_queue<Juli>heap;
struct Brg
{
ll Len;
int Id;
inline bool operator<(const Brg &tmp)const
{
return Len<tmp.Len;
}
}a[N];
int Ans[N];
int main()
{
int i;
R(n); R(m);
for(i=;i<=n;i++)
{
R(Daol[i]); R(Daor[i]);
if(i>) Dis[i-]=(Juli){Daol[i]-Daor[i-],Daor[i]-Daol[i-],i-};
}
sort(Dis+,Dis+n,cmp_Juli);
for(i=;i<=m;i++) a[i]=(Brg){read(),i};
sort(a+,a+m+);
int Now=,cnt=;
// for(i=1;i<n;i++) printf("%d %d\n",Dis[i].Down,Dis[i].Up);
// puts("--------------------------");
for(i=;i<=m;i++)
{
while(Now<n&&a[i].Len>=Dis[Now].Down&&a[i].Len<=Dis[Now].Up) heap.push(Dis[Now++]);
if(heap.empty()) continue;
Juli tmp=heap.top(); heap.pop();
// printf("%d %d %d\n",tmp.Down,tmp.Up,a[i].Len);
if(tmp.Up<a[i].Len) return puts("No"),;
cnt++; Ans[tmp.Id]=a[i].Id;
}
if(cnt<n-) return puts("No"),;
puts("Yes");
for(i=;i<n;i++) W(Ans[i]); puts("");
return ;
}
/*
Input
4 4
1 4
7 8
9 10
12 14
4 5 3 8
Output
Yes
2 3 1 Input
2 2
11 14
17 18
2 9
Output
No Input
2 1
1 1
1000000000000000000 1000000000000000000
999999999999999999
Output
Yes
1 Input
6 9
1 4
10 18
23 29
33 43
46 57
59 77
11 32 32 19 20 17 32 24 32
Output
Yes
1 6 4 5 8
*/

codeforces555B的更多相关文章

随机推荐

  1. B2B、B2C、C2C、O2O分别是什么意思?

    1.B2B 是指进行电子商务交易的供需双方都是商家(或企业.公司),她(他)们使用了互联网的技术或各种商务网络平台,完成商务交易的过程.电子商务是现代 B2B marketing的一种具体主要的表现形 ...

  2. Java 日志系统

    Java 日志系统 1. 创建日志记录器 private final Logger logger = LoggerFactory.getLogger(LoggerTest.class); 2. 打印日 ...

  3. 大数据测试类型&大数据测试步骤

    一.什么是大数据? 大数据是一个大的数据集合,通过传统的计算技术无法进行处理.这些数据集的测试需要使用各种工具.技术和框架进行处理.大数据涉及数据创建.存储.检索.分析,而且它在数量.多样性.速度方法 ...

  4. O051、Create Volume 操作 (Part II)

    参考https://www.cnblogs.com/CloudMan6/p/5612147.html       1.cinder-scheduler 也会启动一个工作流 volume_create_ ...

  5. 简单了解soap协议

    SOAP的是什么的简写 soap是(Simple Object Access Protocal)的简写,即简单对象访问协议,它描述了一种在分散或分布式的环境中如何交换信息的轻量级协议. soap用来干 ...

  6. 【玩转SpringBoot】通过事件机制参与SpringBoot应用的启动过程

    生命周期和事件监听 一个应用的启动过程和关闭过程是归属到“生命周期”这个概念的范畴. 典型的设计是在启动和关闭过程中会触发一系列的“事件”,我们只要监听这些事件,就能参与到这个过程中来. 要想监听事件 ...

  7. Joomla 3.0.0 - 3.4.6 RCE漏洞分析记录

    0x00  前言 今天早上看到了国内几家安全媒体发了Joomla RCE漏洞的预警,漏洞利用的EXP也在Github公开了.我大致看了一眼描述,觉得是个挺有意思的漏洞,因此有了这篇分析的文章,其实这个 ...

  8. MySQL数据库笔记三:数据查询语言(DQL)与事务控制语言(TCL)

    五.数据查询语言(DQL) (重中之重) 完整语法格式: select 表达式1|字段,.... [from 表名 where 条件] [group by 列名] [having 条件] [order ...

  9. 百度云直线在线解析+xdown

    一:在浏览器打开百度云分享链接(推荐Google)百度云分享的链接:https://pan.baidu.com/s/17YQ2x--kOAa_hpapaTcq8Q第二步:打开直线在线解析:https: ...

  10. Hive(七)Hive参数操作和运行方式

    Hive参数操作和运行方式 1.Hive参数操作 1.hive参数介绍 ​ hive当中的参数.变量都是以命名空间开头的,详情如下表所示: 命名空间 读写权限 含义 hiveconf 可读写 hive ...