CF

来源:互联网 发布:python数据分析实战 编辑:程序博客网 时间:2024/05/19 22:07

1.题目描述:

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.

Examples
input
4 41 47 89 1012 144 5 3 8
output
Yes2 3 1 
input
2 211 1417 182 9
output
No
input
2 11 11000000000000000000 1000000000000000000999999999999999999
output
Yes1 
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.


2.题意概述:

有n个岛屿放在同一个条线上,并且把每个岛的左右端点给你。
然后有m条桥,每条桥都有一定的长度。现在让你把桥放在相邻两个岛之间,使得它们能够连通(桥的两端要落在两个岛屿上)。
现在问你,是否存在合法方案,存在则输出方案。不存在则输出"No".

3.解题思路:

首先对于两两相邻的岛屿,根据端点值,我们可以处理出n-1个可放桥的长度区间。
然后对于n-1个区间,根据l值进行升序排序。
再对桥的长度len进行升序排序,用桥来选择区间。
在选择区间过程中,我们只要选择l<=len,r >= len中,r最小的那个作为当前桥所选的区间。
因为对于l <= len的区间,只有r的区别,将两个影响因素转变成一个,然后贪心选择r最小的。
实现中我用set来维护一组l<=len的区间,然后每次取set.begin()。

4.AC代码:

#include <bits/stdc++.h>#define INF 0x3f3f3f3f#define maxn 200100#define N 1111#define eps 1e-6#define pi acos(-1.0)#define e 2.718281828459#define mod (int)1e9 + 7using namespace std;typedef long long ll;typedef unsigned long long ull;int n, m, res[maxn];struct Seg{  ll l, r;  int id;  bool operator<(const Seg &cmp) const  {    return l < cmp.l;  }} a[maxn], c[maxn];struct Len{  ll val;  int id;  bool operator<(const Len &cmp) const  {    if (val == cmp.val)      return id < cmp.id;    return val < cmp.val;  }} b[maxn];bool solve(){  set<Len> st;  int tn = 0;  for (int i = 1; i < n; i++)  {    c[tn].l = a[i].l - a[i - 1].r;    c[tn].r = a[i].r - a[i - 1].l;    c[tn].id = tn;    tn++;  }  sort(c, c + tn);  sort(b, b + m);  for (int i = 0, j = 0; i < m; i++)  {    while (!st.empty() && ((st.begin()->val) < b[i].val))      st.erase(st.begin());    while (j < tn && c[j].l <= b[i].val && c[j].r >= b[i].val)    {      st.insert((Len){c[j].r, c[j].id});      j++;    }    if (st.empty())      continue;    res[st.begin()->id] = b[i].id + 1;    st.erase(st.begin());  }  for (int i = 0; i < tn; i++)    if (res[i] == 0)      return false;  return true;}int main(){#ifndef ONLINE_JUDGE  freopen("in.txt", "r", stdin);  freopen("out.txt", "w", stdout);  long _begin_time = clock();#endif  while (~scanf("%d%d", &n, &m))  {    memset(res, 0, sizeof(res));    for (int i = 0; i < n; i++)      scanf("%I64d%I64d", &a[i].l, &a[i].r);    for (int i = 0; i < m; i++)    {      scanf("%I64d", &b[i].val);      b[i].id = i;    }    if (solve())    {      puts("Yes");      for (int i = 0; i < n - 1; i++)        printf("%d ", res[i]);      puts("");    }    else      puts("No");  }#ifndef ONLINE_JUDGE  long _end_time = clock();  printf("time = %ld ms.", _end_time - _begin_time);#endif  return 0;}

0 0
原创粉丝点击