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

10111 단어 codeforces
B. Case of Fugitive
Time Limit: 20 Sec
Memory Limit: 256 MB
제목 연결
http://codeforces.com/contest/555/problem/B
Description
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.
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 Input
4 41 47 89 1012 144 5 3 8
Sample Output
Yes2 3 1
HINT
 
제목
한 줄 의 섬 이 있 습 니 다. 그리고 m 개의 다리 에서 n 개 를 선택 한 다음 에 이 섬 에 걸 쳐 인접 한 섬 을 연결 시 키 고 수출 방안 을 제시 하 라 고 합 니 다.
문제 풀이:
처음에 뇌 보 는 가장 큰 흐름 을 달 리 는 것 이 었 다. 그리고 복잡 도 를 생각 했 으 니 욕심 을 내 서 하 는 것 이 좋 겠 다.
먼저 각 다리 가 놓 을 수 있 는 구간 을 찾 은 후에 정렬 하여 오른쪽 단점 보다 작은 최대 치 를 찾 아 라.
그리고 됐어 요.
그 중에서 출력 번호 가 비교적 번 거 로 우 니 우리 pair 하면 좋 겠 다.
코드
 
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef unsigned long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 2000001
#define mod 1000000007
#define eps 1e-9
int Num;
char CH[20];
const int inf=0x3f3f3f3f;
inline ll read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

//**************************************************************************************

set<pair<ll,int> >s;
pair<pair<ll,ll>,int> br[maxn];
pair<ll,ll> a[maxn];
set<pair<ll,int> >::iterator it;
int ans[maxn];
int main()
{
    int n=read(),m=read();
    for(int i=0;i<n;i++)
        cin>>a[i].first>>a[i].second;
    for(int i=0;i<n-1;i++)
        br[i]=make_pair(make_pair(a[i].second-a[i+1].first,a[i].first-a[i+1].second),i);
    for(int i=0;i<m;i++)
    {
        ll kiss;
        cin>>kiss;
        s.insert(make_pair(kiss,i));
    }
    sort(br,br+n-1);
    for(int i=0;i<n-1;i++)
    {
        ll l=-br[i].first.first,r=-br[i].first.second;
        it=s.lower_bound(make_pair(r,inf));
        if(it==s.begin())
            return puts("No");
        it--;
        if(it->first<l)
            return puts("No");
        ans[br[i].second]=it->second;
        s.erase(it);
    }
    puts("Yes");
    for(int i=0;i<n-1;i++)
        cout<<ans[i]+1<<" ";
}

좋은 웹페이지 즐겨찾기