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的更多相关文章
随机推荐
- nnginx配置代理服务器
因为有些服务有ip白名单的限制,部署多节点后ip很容易就不够用了,所以可以将这些服务部署到其中的一些机器上, 并且部署代理服务器,然后其余机器以代理的方式访问服务.开始是以tinyproxy作为代理服 ...
- javascript——定义函数方式
1:有名函数定义方式 2:匿名函数定义方法 https://www.cnblogs.com/wl0000-03/p/6050108.html console.log(add(3,6)); (funct ...
- javascript是否像php一样有isset和empty?
javascript是否像php一样有isset和empty? is set()在php中用于检测是否设置了变量木浴桶,函数返回布尔值true/false.在javascript中,您可以用替换它!( ...
- GitHub使用--01
1.Git下载与安装 Git网站下载地址https://git-scm.com/downloads 2.本地Git使用 在存储代码仓库的文件夹下右键 git bash here 初始化仓库 git i ...
- 解决npm安装node-sass太慢及编译错误问题
环境: win7 node v8.11.1 npm v5.6.0 背景: 最近vue项目使用sass,所以需要sass-loader,sass-loader依赖node-sass,还需安装node-s ...
- 第十章、json和pickle模块
目录 第十章.json和pickle模块 一.序列化 二.json 三.pickle模块 第十章.json和pickle模块 一.序列化 把对象(变量)从内存中变成可存储或传输的过程称之为序列化, 序 ...
- 6、SSH远程管理服务实战
1.SSH基本概述 SSH是一个安全协议,在进行数据传输时,会对数据包进行加密处理,加密后在进行数据传输.确保了数据传输安全.那SSH服务主要功能有哪些呢? 1.提供远程连接服务器的服务. 2.对传输 ...
- Linux下kafka集群搭建
环境准备 zookeeper集群环境 kafka是依赖于zookeeper注册中心的一款分布式消息对列,所以需要有zookeeper单机或者集群环境. 三台服务器: 172.16.18.198 k8s ...
- C++虚函数作用原理(一)——虚函数如何在C++语言逻辑中存在
C++多态,接触其实也没太长的时间.上课的时候老师总是不停的讲,多态可以实现利用一个基类对象调用不同继承类的成员函数.我就会觉得很伤脑筋,这个的原理到底是什么?是什么呢? 开始的时候我觉得自己应该能够 ...
- [APIO2010] 算法竞赛竞赛经典 巡逻
原题链接 题目描述 在一个地区有 n 个村庄,编号为1,2,-,n. 有 n-1 条道路连接着这些村庄,每条道路刚好连接两个村庄,从任何一个村庄,都可以通过这些道路到达其他任一个村庄. 每条道路的长度 ...