Codeforces Round #310 (Div. 1) B. Case of Fugitive(set二分)
#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 second typedef 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; }