codeforces555B
Case of Fugitive
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 ≤ ri, li + 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
4 4
1 4
7 8
9 10
12 14
4 5 3 8
Yes
2 3 1
2 2
11 14
17 18
2 9
No
2 1
1 1
1000000000000000000 1000000000000000000
999999999999999999
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的更多相关文章
随机推荐
- Qt5.8.0编译QtMqtt库并使用该库连接有人云的例子
一 编译QtMqtt库Qt5.10才官方支持MQTT,但我用的Qt版本是5.8.0 Mingw_32BIT, 为了在Qt5.8.0上添加MQTT支持,需要自己编译源码 步骤: (1) git clon ...
- HDU3622 Bomb Game(二分+2-SAT)
题意 给n对炸弹可以放置的位置(每个位置为一个二维平面上的点), 每次放置炸弹是时只能选择这一对中的其中一个点,每个炸弹爆炸 的范围半径都一样,控制爆炸的半径使得所有的爆炸范围都不相 交(可以相切), ...
- 【转】js小数转百分比
转自:js小数和百分数的转换 function toPercent(point){ var str=Number(point*100).toFixed(1); str+="%"; ...
- 使用JavaFX开发桌面程序(一)
使用JavaFX开发桌面程序 注:我也是JAVA FX的初学者之一,自己在学习的时候踩了许多的坑,中文英文的资料查了不少,但是觉得FX技术和其他热门技术相比,教程还是太少了.这里就尽量做一点微小的贡献 ...
- springboot-oracle工程win下正常,centos下不能访问数据库
工程在win下正常运行,部署到centos下出现下述异常: ### Error querying database. Cause: org.springframework.jdbc.CannotGet ...
- ASP.NET数据库连接类(SqlDBHelper)
第一步:创建一个名为SqlDBHelper的类,用来作为联通数据库和系统之间的桥梁. 第二步:引入命名空间,如果System.Configuration.System.Transcations这两个命 ...
- Java学习笔记【七、时间、日期、数字】
参考:http://www.runoob.com/java/java-date-time.html Date类 构造: Date() 使用当前的日期时间 Date(long millisec) 197 ...
- 原创博客>>>解决粘包问题的方法
目录 原创博客>>>解决粘包问题的方法 原创博客>>>解决粘包问题的方法 服务端: import socket import struct service=sock ...
- IoT 设备通信安全讨论
IoT 设备通信安全讨论 作者:360CERT 0x00 序言 IoT 设备日益增多的今天,以及智能家居这一话题愈发火热,智能家居市场正在飞速的壮大和发展,无数 IoT 设备正在从影片中不断的走向用户 ...
- Winfrom TextBox 添加水印文字 + 字体颜色
using System.Drawing; using System.Windows.Forms; namespace KK.WaterMark.Control { public partial cl ...