ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

codeforces555B

2019-06-15 22:53:37  阅读:225  来源: 互联网

标签:bridge ch li codeforces555B between line ri


Case of Fugitive

 CodeForces - 555B 

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 adjacentislands. 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 + 1and 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 - 1numbers 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.

 

sol:把桥按照长度从小到大排序,对于每两座岛之间的桥长是一个闭区间[L,R]

对于桥一个个枚举过去,如当前桥长是a,对于所有L<=a的找到R最小的那个,贪心一遍即可

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll read()
{
    ll s=0;
    bool f=0;
    char ch=' ';
    while(!isdigit(ch))
    {
        f|=(ch=='-'); ch=getchar();
    }
    while(isdigit(ch))
    {
        s=(s<<3)+(s<<1)+(ch^48); ch=getchar();
    }
    return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
    if(x<0)
    {
        putchar('-'); x=-x;
    }
    if(x<10)
    {
        putchar(x+'0'); return;
    }
    write(x/10);
    putchar((x%10)+'0');
    return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=200005;
int n,m;
ll Daol[N],Daor[N];
struct Juli
{
    ll Down,Up,Id;
    inline bool operator<(const Juli &tmp)const
    {
        return Up>tmp.Up;
    }
}Dis[N];
inline bool cmp_Juli(Juli p,Juli q)
{
    return p.Down<q.Down;
}
priority_queue<Juli>heap;
struct Brg
{
    ll Len;
    int Id;
    inline bool operator<(const Brg &tmp)const
    {
        return Len<tmp.Len;
    }
}a[N];
int Ans[N];
int main()
{
    int i;
    R(n); R(m);
    for(i=1;i<=n;i++)
    {
        R(Daol[i]); R(Daor[i]);
        if(i>1) Dis[i-1]=(Juli){Daol[i]-Daor[i-1],Daor[i]-Daol[i-1],i-1};
    }
    sort(Dis+1,Dis+n,cmp_Juli);
    for(i=1;i<=m;i++) a[i]=(Brg){read(),i};
    sort(a+1,a+m+1);
    int Now=1,cnt=0;
//    for(i=1;i<n;i++) printf("%d %d\n",Dis[i].Down,Dis[i].Up);
//    puts("--------------------------");
    for(i=1;i<=m;i++)
    {
        while(Now<n&&a[i].Len>=Dis[Now].Down&&a[i].Len<=Dis[Now].Up) heap.push(Dis[Now++]);
        if(heap.empty()) continue;
        Juli tmp=heap.top(); heap.pop();
//        printf("%d %d %d\n",tmp.Down,tmp.Up,a[i].Len);
        if(tmp.Up<a[i].Len) return puts("No"),0;
        cnt++; Ans[tmp.Id]=a[i].Id;
    }
    if(cnt<n-1) return puts("No"),0;
    puts("Yes");
    for(i=1;i<n;i++) W(Ans[i]); puts("");
    return 0;
}
/*
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 

Input
6 9
1 4
10 18
23 29
33 43
46 57
59 77
11 32 32 19 20 17 32 24 32
Output
Yes
1 6 4 5 8 
*/
View Code

 

标签:bridge,ch,li,codeforces555B,between,line,ri
来源: https://www.cnblogs.com/gaojunonly1/p/11029161.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有