D. Case of Fugitive
time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

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.

题意:n-1个区间 m个数

数要满足的条件是大于等于左区间 小于等于又区间  问着m个数中有没有n-1个数满足这些区间(一个数不能重复满足多个区间)

区间按左从小到大排序 用个优先队列维护区间右边的值

 #include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<bitset>
#include<set>
#include<map>
#include<time.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=+;
const int inf=0x3f3f3f3f;
struct node{
ll l,r;
int pos;
friend bool operator<(node aa,node bb){
return aa.r>bb.r;
}
}a[N];
struct Node{
ll x;int pos;
}b[N];
bool cmp1(node aa,node bb){
return aa.l<bb.l;
}
bool cmp2(Node aa,Node bb){
return aa.x<bb.x;
}
priority_queue<node>q;
int ans[N];
int main(){
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
ll l,r;
scanf("%I64d%I64d",&l,&r);
int t=;
ll x,y;
for(int i=;i<n;i++){
scanf("%I64d%I64d",&x,&y);
ll t1=x;
ll t2=y;
a[++t].l=x-r;
a[t].r=y-l;
a[t].pos=i;
l=t1;r=t2;
}
sort(a+,a+t+,cmp1);
for(int i=;i<=m;i++){
scanf("%I64d",&b[i].x);
b[i].pos=i;
}
sort(b+,b++m,cmp2);
int k=;
int flag=;
int cnt=;
for(int i=;i<=m;i++){
x=b[i].x;
for(int j=k;j<=t;j=k){
if(a[j].l<=x&&a[j].r>=x){
q.push(a[j]);k++;
}
else{
break;
}
}
if(q.empty())continue;
node aa=q.top();q.pop();
if(x>aa.r){
flag=;
break;
}
cnt++;
//cout<<cnt<<endl;
ans[aa.pos]=b[i].pos;
}
if(cnt<t||flag){
cout<<"No"<<endl;continue;
}
cout<<"Yes"<<endl;
for(int i=;i<=t;i++)cout<<ans[i]<<" ";
cout<<endl;
}
}

CodeForces - 556D的更多相关文章

  1. Codeforces 556D Restructuring Company

    传送门 D. Restructuring Company time limit per test 2 seconds memory limit per test 256 megabytes input ...

  2. Codeforces 556D - Case of Fugitive

    556D - Case of Fugitive 思路:将桥长度放进二叉搜索树中(multiset),相邻两岛距离按上限排序,然后二分查找桥长度匹配并删除. 代码: #include<bits/s ...

  3. CodeForces - 556D Case of Fugitive (贪心+排序)

    Andrewid the Android is a galaxy-famous detective. He is now chasing a criminal hiding on the planet ...

  4. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  9. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

随机推荐

  1. 用 webpack 实现持久化缓存

    什么是持久化缓存? 原文链接https://sebastianblade.com/using-webpack-to-achieve-long-term-cache/ 缓存(cache)一直是前端性能优 ...

  2. OpenGL坐标系之间的转换 http://blog.csdn.net/sac761/article/details/52179585

    1. OpenGL 渲染管线 OpenGL渲染管线分为两大部分,模型观测变换(ModelView Transformation)和投影变换(Projection Transformation).做个比 ...

  3. VS2010编译错误:fatal error C1189: #error : This file requires _WIN32_WINNT to be #defined at least to 0x

    下面是彻底解决方法:在工程的stdafx.h中添加(如有类似语句,需注释掉)#ifndef WINVER // Allow use of features specific to Windows 95 ...

  4. nginx平滑升级实战

    Nginx 平滑升级 1.查看旧版Nginx的编译参数 [root@master ~]# /usr/local/nginx/sbin/nginx -V [root@master ~]# ll ngin ...

  5. 浅析Oracle中的不等于号

    前几天碰到一个关于Oracle不等于的问题,最后搜索了一下,发现下面资料,拿来跟大家分享一下,需要的朋友可以参考下     关于Oracle中的不等于号: 在Oracle中, <> != ...

  6. xmpp登录(2)

    XMPP中常用对象们: XMPPStream:xmpp基础服务类 XMPPRoster:好友列表类 XMPPRosterCoreDataStorage:好友列表(用户账号)在core data中的操作 ...

  7. linux的ssh相关指令

    1.安装ssh apt-get install openssh-server 2.备份ssh的配置文件 sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_confi ...

  8. python3支持excel读写

    1.安装setuptools-17.0.tar.gz cmd 进入命令行 cd C:\Users\vivi\Desktop\pythonforexcel\setuptools-17.0\setupto ...

  9. open random

    open文件操作 f = open('文件路径',mode='rwab+',encoding='utf-8') # content = f.read(3) # 读出来的都是字符 # f.seek(3) ...

  10. Spring核心技术(四)——Spring的依赖及其注入(续二)

    前面两篇文章描述了IoC容器中依赖的概念,包括依赖注入以及注入细节配置.本文将继续描述玩全部的依赖信息. 使用 depends-on 如果一个Bean是另一个Bean的依赖的话,通常来说这个Bean也 ...