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

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 ofnnarrow islands located in a row. For more comfort let’s represent them as non-intersecting segments on a straight line: islandihas coordinates[li,ri], besides,ri<li+1for1≤i≤n-1.

To reach the goal, Andrewid needs to place a bridge between each pair ofadjacentislands. A bridge of lengthacan be placed between thei-th and the(i+1)-th islads, if there are such coordinates ofxandy, thatli≤x≤ri,li+1≤y≤ri+1andy-x=a.

The detective was supplied withmbridges, 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 integersn(2≤n≤2·105) andm(1≤m≤2·105) — the number of islands and bridges.

Nextnlines each contain two integersliandri(1≤li≤ri≤1018) — the coordinates of the island endpoints.

The last line containsmintegernumbersa1,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 printn-1numbersb1,b2,…,bn-1, which mean that between islandsiandi+1there must be used a bridge numberbi.

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 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.

#include <bits/stdc++.h>#define foreach(it,v) for(__typeof(v.begin()) it = v.begin(); it != v.end(); ++it)using namespace std;typedef long long ll;const int maxn = 2e5 + 10;#define x first#define y secondtypedef pair<ll,ll> pll;typedef pair<pll,ll> plll;typedef plll Seg;typedef pll Bridge;bool cmpSeg(const Seg & a, const Seg & b){pll ta = a.x, tb = b.x;if(ta.y == tb.y) return ta.x < tb.x;return ta.y < tb.y;}Seg p[maxn];Bridge a[maxn];ll l[maxn],r[maxn],ans[maxn];int main(int argc, char const *argv[]){ios_base::sync_with_stdio(false);cin.tie(0);int n,m;while(cin>>n>>m) {for(int i = 1; i <= n; i++) {cin>>l[i]>>r[i];}for(int i = 1; i < n; i++) {p[i-1].x.x = l[i+1] – r[i];p[i-1].x.y = r[i+1] – l[i];p[i-1].y = i-1;}sort(p,p+n-1,cmpSeg);set<Bridge>Q;for(int i = 1; i <= m; i++) {ll a,id = i;cin>>a;Q.insert(make_pair(a,id));}set<Bridge>::iterator it;bool ok = (m + 1 >= n);for(int i = 0; i < n-1; i++) {if(!ok) break;it = Q.lower_bound(make_pair(p[i].x.x,0LL));if(it==Q.end()||it->x > p[i].x.y) {ok = false;break;}ans[p[i].y] = it->y;Q.erase(it);}if(ok) {cout<<"Yes\n";for(int i = 0; i < n-1; i++)cout<<ans[i]<<" ";cout<<"\n";}else cout<<"No\n";}return 0;}

版权声明:本文为博主原创文章,未经博主允许不得转载。

,接受失败等于回归真实的自我,接受失败等于打破完美的面具,

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

相关文章:

你感兴趣的文章:

标签云: