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.
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.
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.
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
用一些桥把岛连接起来,岛和桥都看成线段,设桥的两个端点是x,y,要满足li ≤ x ≤ ri, li + 1 ≤ y ≤ ri + 1且y - x = a且。给出M个桥,问相邻的岛之间是否都能建上桥。如果能的话按建立顺序输出一组满足条件的桥的编号。
设两个岛之间最短间隔为l,最长间隔为r。把间隔按l从小到大排序,桥的长度也按从小到大排序,然后按从小到大的顺序对桥扫一遍,对于一个桥,找出l比它小,r比它大并且r尽量小的间隔进行匹配。在扫的过程中,用优先队列保存间隔l不小于当前桥长度的,然后每次取出r最小的那个,如果r不小于桥的长度就匹配,否则这个间隔肯定是匹配不了桥的,因为后面的桥的长度更大。
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef long long LL;
const LL MAXN=200010;
const LL SIZE=4096;
const LL INF=0x3f3f3f3f;
LL N,M;
LL l[MAXN],r[MAXN],ans[MAXN];
struct St{
LL l,r,id;
bool operator < (const St& rhs) const{
return r>rhs.r;
}
}a[MAXN];
struct St2{
LL len,id;
bool operator < (const St2& rhs) const{
return len<rhs.len;
}
}b[MAXN];
bool cmp(St a,St b){
return a.l<b.l;
}
priority_queue<St> q;
int main(){
freopen("in.txt","r",stdin);
while(scanf("%I64d%I64d",&N,&M)!=EOF){
for(LL i=1;i<=N;i++) scanf("%I64d%I64d",&l[i],&r[i]);
LL k=0;
for(LL i=2;i<=N;i++){
a[k].r=r[i]-l[i-1];
a[k].l=l[i]-r[i-1];
a[k].id=i-2;
k++;
}
sort(a,a+k,cmp);
for(LL i=0;i<M;i++){
scanf("%I64d",&b[i].len);
b[i].id=i+1;
}
sort(b,b+M);
while(!q.empty()) q.pop();
LL j=0,cnt=0;
for(LL i=0;i<M;i++){
for(;j<k;j++){
if(a[j].l<=b[i].len) q.push(a[j]);
else break;
}
if(!q.empty()){
St tmp=q.top();
q.pop();
if(tmp.r>=b[i].len){
ans[tmp.id]=b[i].id;
cnt++;
}
else break;
}
}
if(cnt<k) printf("No\n");
else{
printf("Yes\n");
for(LL i=0;i<k-1;i++) printf("%I64d ",ans[i]);
printf("%I64d\n",ans[k-1]);
}
}
return 0;
}