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.


#include <bits/stdc++.h>
#define foreach(it,v) for(__typeof(v.begin()) it = v.begin(); it != v.end(); ++it)
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
#define x first
#define y second
typedef pair<ll,ll> pll;
typedef pair<pll,ll> plll;
typedef plll Seg;
typedef pll Bridge;
bool cmpSeg(const Seg & a, const Seg & b)
{
pll ta = a.x, tb = b.x;
if(ta.y == tb.y) return ta.x < tb.x;
return ta.y < tb.y;
}
Seg p[maxn];
Bridge a[maxn];
ll l[maxn],r[maxn],ans[maxn];
int main(int argc, char const *argv[])
{
ios_base::sync_with_stdio(false);cin.tie(0);
int n,m;
while(cin>>n>>m) {
for(int i = 1; i <= n; i++) {
cin>>l[i]>>r[i];
}
for(int i = 1; i < n; i++) {
p[i-1].x.x = l[i+1] - r[i];
p[i-1].x.y = r[i+1] - l[i];
p[i-1].y = i-1;
}
sort(p,p+n-1,cmpSeg);
set<Bridge>Q;
for(int i = 1; i <= m; i++) {
ll a,id = i;cin>>a;
Q.insert(make_pair(a,id));
}
set<Bridge>::iterator it;
bool ok = (m + 1 >= n);
for(int i = 0; i < n-1; i++) {
if(!ok) break;
it = Q.lower_bound(make_pair(p[i].x.x,0LL));
if(it==Q.end()||it->x > p[i].x.y) {
ok = false;
break;
}
ans[p[i].y] = it->y;
Q.erase(it);
}
if(ok) {
cout<<"Yes\n";
for(int i = 0; i < n-1; i++)cout<<ans[i]<<" ";
cout<<"\n";
}else cout<<"No\n";
}
return 0;
}

最新文章

  1. Opera 浏览器各版本下载地址
  2. [USACO14OPEN] Dueling GPS&#39;s[最短路建模]
  3. android——从零开始
  4. CenOS下搭建VPN服务
  5. html5 拖拽
  6. linux exec函数族
  7. Tomcat设置最佳线程数总结
  8. 搭建git远程服务器三步骤
  9. ssm简单搭建
  10. Codeforces 853B Jury Meeting (差分+前缀和)
  11. rabbitmq 生产者 消费者(多个线程消费同一个队列里面的任务。) 一个通用rabbitmq消费确认,快速并发运行的框架。
  12. ssm框架结合axis2实例步骤
  13. 测试webservice的时候,如果出现这个错误:&quot;The test form is only available for requests from the local machine&quot;
  14. stenciljs 学习六 组件开发样式指南
  15. [UE4]机器人自动寻路
  16. 2.4G无线控制器附加AT2401C功放IC增加距离
  17. iOS彩票项目--第一天,自定义TabBar控制器和自定义TabBar,自定义导航控制器
  18. 使用Apache HttpClient 4.x进行异常重试
  19. 选择LoadRunner Protocol的两大定律
  20. 有用的 Angular CLI 命令参数

热门文章

  1. oracle exp/imp命令详解
  2. 错误:update 忘了加 where
  3. Android 4.4 Kitkat Phone工作流程浅析(八)__Phone状态分析
  4. java collection.frequency方法
  5. intellij idea 无法启动或调试 spring-boot
  6. IOS应用提交所需的ICON
  7. mongodb centos7上的安装
  8. sys.usb.config webcam
  9. Android性能检测工具——traceview
  10. Android实现图片裁剪