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

B. 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 ≤ rili + 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 test(s)
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.

/**
CF555B 贪心
题目大意:给定一些不连续的区间用给定长度的线段将这些区间连起来。要求线段长度的两个顶点必须在连接的两个区间上,
问能否够将全部的区间连接成一个区间
解题思路:对于每个要连接的空隙(即相邻的两个区间之间的部分)求出可用线段的最短长度x和最长长度y,依照x递减,x相等y递减的
方式排序。将须要的线段放到给set中。从前到后遍历空隙。每次取第一个长度小于等于y的线段。假设改线段大于等于x。
则循环继续进行,否则跳出循环,输出No
*/
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <iostream>
#include <set>
using namespace std;
typedef long long LL;
pair <pair<LL,LL>,int>p[200005];
set<pair<LL,int> >mp;
set<pair<LL,int> >::iterator k;
int s[200005],n,m; int main()
{
LL u,v,x,y;
while(~scanf("%d%d",&n,&m))
{
for(int i=0; i<n; i++)
{
scanf("%I64d%I64d",&x,&y);
if(i>0)
{
p[i]=make_pair(make_pair(v-x,u-y),i);
///printf("%d->%I64d %I64d\n",i,p[i].first.first,p[i].first.second);
}
u=x;
v=y;
}
mp.clear();
for(int i=1; i<=m; i++)
{
scanf("%I64d",&x);
mp.insert(make_pair(x,i));
}
sort(p+1,p+n);
int flag=1;
for(int i=1; i<n; i++)
{
x=-p[i].first.first;
y=-p[i].first.second;
//printf("%I64d %I64d\n",x,y);
k=mp.lower_bound(make_pair(y,1<<30));
if(k==mp.begin())
{
puts("No");
flag=0;
break;
}
k--;
if(k->first<x)
{
puts("No");
flag=0;
break;
}
s[p[i].second]=k->second;
mp.erase(k);
}
if(flag)
{
puts("Yes");
for(int i=1; i<n; i++)
{
printf(i==n-1?"%d\n":"%d ",s[i]);
}
}
}
return 0;
}

CF555B 贪心的更多相关文章

  1. BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]

    1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][St ...

  2. HDOJ 1051. Wooden Sticks 贪心 结构体排序

    Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  3. HDOJ 1009. Fat Mouse' Trade 贪心 结构体排序

    FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. BZOJ 1691: [Usaco2007 Dec]挑剔的美食家 [treap 贪心]

    1691: [Usaco2007 Dec]挑剔的美食家 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 786  Solved: 391[Submit][S ...

  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. 【BZOJ-4245】OR-XOR 按位贪心

    4245: [ONTAK2015]OR-XOR Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 486  Solved: 266[Submit][Sta ...

  7. code vs 1098 均分纸牌(贪心)

    1098 均分纸牌 2002年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解   题目描述 Description 有 N 堆纸牌 ...

  8. 【BZOJ1623】 [Usaco2008 Open]Cow Cars 奶牛飞车 贪心

    SB贪心,一开始还想着用二分,看了眼黄学长的blog,发现自己SB了... 最小道路=已选取的奶牛/道路总数. #include <iostream> #include <cstdi ...

  9. 【贪心】HDU 1257

    HDU 1257 最少拦截系统 题意:中文题不解释. 思路:网上有说贪心有说DP,想法就是开一个数组存每个拦截系统当前最高能拦截的导弹高度.输入每个导弹高度的时候就开始处理,遍历每一个拦截系统,一旦最 ...

随机推荐

  1. 学习JUnit

    一.为什么测试很重要? 塑造系统的设计.我们知道输入和输出应该是什么样的,但是我们需要创建什么对象来做到这一点呢?代码应该塑造成什么样的"形状"?编写测试可以让我们知道应该创建什么 ...

  2. 奇葩属性:layout_weight 的解释及使用

    在Android的控件布局中,有一个奇葩的 layout_weight 属性,定义如下: layout_weight : 用于指定剩余空闲空间的分割比例.用法: 01 <LinearLayout ...

  3. Android学习系列(3)--App自动更新之自定义进度视图和内部存储

    友好的视觉感知和稳定的不出错表现,来自于我们追求美感和考虑的全面性,博客园从技术的角度,一直我都很欣赏.这篇文章是android开发人员的必备知识,是我特别为大家整理和总结的,不求完美,但是有用. 这 ...

  4. 【js】appendChild

    appendChild主要是用来追加节点插入到最后:循环的时候由于不停的搬家导致length在改变.     使用for循环 <!Doctype html> <html xmlns= ...

  5. DataTime? 的 GetValueOrDefault() 方法

    DataTime? 转换为 DataTime类型 就可以调用 ToString()  自定义格式 @item.CreateDate.GetValueOrDefault().ToString(" ...

  6. oracle导入sql文件,并且记录日志

    一.导入.sql文件 @data.sql 二.记录日志: 1.输入命令  sqlplus 数据库名/密码@数据库   按回车键 2.输入spool  指定路径:\a.log    按回车键  (此步骤 ...

  7. struts2每次访问都会创建一个新的session

    1.第一次 项目在测试过程中,突然发现登陆之后再去访问其他菜单时都会提示未登录: 查看日志之后发现是因为很多次请求时都会自动创建一个新的session,这就费解了, 因为之前也没改动什么session ...

  8. 从一到面试题了解js异步机制:setTimeout 和 Pronmise

    1.毫无疑问setTimeout是最晚输出的 2.请无视undefined,这是浏览器的返回值. 3.new Promise中并不是异步,而.then()后才是异步.

  9. 利用ichart绘制网页图表

    首先,最好的教程在这里:ichartjs 有了这个网站,要绘制网页图表简直方便愉快! 接下来说一下使用方法~~~ 进入网站,点击在线设计器 在线设计器的使用方法就不说了,摸索一下就会了!关键在于两个地 ...

  10. ASP.NET的一些小问题

    如何获取网站当前绝对路径? string path = HttpRuntime.AppDomainAppVirtualPath; 注:该路径结尾不含'/'.