Codeforces Round #310 (Div. 1) B. Case of Fugitive

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.

n logn,注意要用long long ，优化一下读取方法，能快不少！

```#define N 200050
#define MOD -1000000007
int n,m,ans[N];
long long x[N],y[N];
struct node{
int type,in;
long long x;
node(long long  xx,int typee){
x = xx;type = typee;
}
node(){
x = 0;type = 0;in = 0;
}
bool operator < (const node  t) const {
return (x < t.x);
}
};
struct bridge{
long long  v;
int in;
bridge(long long  vv,int inn){
v = vv;in = inn;
}
bridge(){
v = 0;in = 0;
}
bool operator < (const bridge  t) const {
return v<t.v;
}
};
bridge bridges[N];
node nodes[2 * N];
multiset<bridge> mysets;
multiset<bridge>::iterator it;
inline ll getnum()
{
char c = getchar();
ll num,sign=1;
for(;c<'0'||c>'9';c=getchar())if(c=='-')sign=-1;
for(num=0;c>='0'&&c<='9';)
{
c-='0';
num = num*10+c;
c=getchar();
}
return num*sign;
}
int main()
{
while (S2(n,m) != EOF)
{
FI(n){
//cin>>x[i]>>y[i];
x[i] = getnum();
y[i] = getnum();
}
n--;
FI(n){
nodes[2 * i].x = x[i + 1] - y[i];
nodes[2 * i].type = 0;
nodes[2 * i].in = i;
nodes[2 * i + 1].x = y[i+1] - x[i];
nodes[2 * i + 1].type = 1;
nodes[2 * i + 1].in = i;
x[i] = nodes[2 * i].x;
y[i] = nodes[2 * i + 1].x;
}
FI(m){
// cin>>bridges[i].v;
bridges[i].v = getnum();
bridges[i].in = i + 1;
}
sort(nodes,nodes+2 * n);
mysets.clear();
FI(m){
mysets.insert(bridges[i]);
}
int i;
for(i=0;i<2 * n;i++){
if(nodes[i].type){
int index = nodes[i].in;
bool flag = false;
if(mysets.empty())
break;
it = mysets.lower_bound(bridge(x[index],0));
if(it != mysets.end()){
if(it->v >= x[index] && it->v <= y[index]){
ans[index] = it->in;
mysets.erase(it);
flag = true;
continue;
}
if(it->v > y[index]){
break;
}
}
if(!flag)
break;
}
}
if(i == 2 * n){
printf("Yes\n");
FI(n){
if(i){
printf(" %d",ans[i]);
}
else {
printf("%d",ans[i]);
}
}
printf("\n");
}
else {
printf("No\n");
}
}
return 0;
}```