Distributing Parts CodeForces

来源:互联网 发布:淘宝代购衣服专柜真假 编辑:程序博客网 时间:2024/06/10 22:38

You are an assistant director in a new musical play. The play consists of n musical parts, each part must be performed by exactly one actor. After the casting the director chosem actors who can take part in the play. Your task is to assign the parts to actors. However, there are several limitations.

First, each actor has a certain voice range and there are some parts that he cannot sing. Formally, there are two integers for each actor,ci anddi (ci ≤ di) — the pitch of the lowest and the highest note that the actor can sing. There also are two integers for each part — aj and bj (aj ≤ bj) — the pitch of the lowest and the highest notes that are present in the part. The i-th actor can perform thej-th part if and only if ci ≤ aj ≤ bj ≤ di, i.e. each note of the part is in the actor's voice range.

According to the contract, the i-th actor can perform at mostki parts. Besides, you are allowed not to give any part to some actors (then they take part in crowd scenes).

The rehearsal starts in two hours and you need to do the assignment quickly!

Input

The first line contains a single integer n — the number of parts in the play (1 ≤ n ≤ 105).

Next n lines contain two space-separated integers each,aj andbj — the range of notes for thej-th part (1 ≤ aj ≤ bj ≤ 109).

The next line contains a single integer m — the number of actors (1 ≤ m ≤ 105).

Next m lines contain three space-separated integers each,ci,di andki — the range of thei-th actor and the number of parts that he can perform (1 ≤ ci ≤ di ≤ 109,1 ≤ ki ≤ 109).

Output

If there is an assignment that meets all the criteria aboce, print a single word "YES" (without the quotes) in the first line.

In the next line print n space-separated integers. Thei-th integer should be the number of the actor who should perform thei-th part. If there are multiple correct assignments, print any of them.

If there is no correct assignment, print a single word "NO" (without the quotes).

Example
Input
31 32 43 521 4 22 5 1
Output
YES1 1 2
Input
31 32 43 521 3 22 5 1
Output
NO

题意:这里有一些歌剧和演员,每个演员有一个声域L,R,并且这个演员只可以出演k个歌剧,每个歌剧也需要一个声域至少覆盖L,R的演员才能出演,现在要求每个歌剧都要有一个演员去演请问该怎么分配,


第一眼看上去,我擦,网络流,二分图最大匹配,一看数据范围,发现不对了.......仔细想了想,是个贪心

思路如下:首先让歌剧和演员都按照他们的音域的R来排序,然后逐个考虑演员,把所有R小于当前考虑的演员的音域都加入set里面,然后找到L最接近演员L的,并让这个演员出演这个歌剧,如果找不到,就考虑下一个演员

代码如下:

#include <bits/stdc++.h>using namespace std;const int maxn = 1000005;struct node{    int l,r,pos,k;};node part[maxn],actor[maxn];bool cmp(node a,node b){    return a.r<b.r;}int ans[maxn];set<pair<int,int> >s;int main(){    s.clear();    memset(ans,0,sizeof(ans));    int n,m;    cin>>n;    for(int i=1;i<=n;i++){        scanf("%d%d",&part[i].l,&part[i].r);        part[i].pos=i;    }    cin>>m;    for(int i=1;i<=m;i++){        scanf("%d%d%d",&actor[i].l,&actor[i].r,&actor[i].k);        actor[i].pos=i;    }    sort(part+1,part+1+n,cmp);    sort(actor+1,actor+1+m,cmp);    int i=1,j=1,ok=0;    while(j<=m){        if(i<=n && part[i].r<=actor[j].r){            s.insert(make_pair(part[i].l,part[i].pos));            i++;        }        else{            set<pair<int,int> >::iterator it;            it=s.lower_bound(make_pair(actor[j].l,0));            if(it==s.end()){                if(j==m && s.size()>0){//如果s不为空,并且最后一个演员没有歌剧演说明扔到s里面的某些歌剧没人演                    ok=1;                    break;                }                else{                    j++;                    continue;                }            }            ans[it->second]=actor[j].pos;            s.erase(it);            actor[j].k--;            if(actor[j].k==0)j++;//只有当这个演员不能再用的时候再考虑下一个演员        }    }    for(int i=1;i<=n;i++)if(ans[i]==0)ok=1;    if(!ok){        cout<<"YES"<<endl;        cout<<ans[1];        for(int i=2;i<=n;i++)printf(" %d",ans[i]);        cout<<endl;    }    else{        cout<<"NO"<<endl;    }}


原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 嗓子卡了小鱼刺怎么办 骨头卡在喉咙里怎么办 卡刺喉咙怎么办小窍门 中百购物卡过期怎么办 得仕卡过期了怎么办 超市购物卡丢了怎么办 中石化油卡丢失怎么办 etc同车换车牌了怎么办 石油加油卡丢了怎么办 石化加油卡丢了怎么办 怎么办中石化的加油卡 中石油油卡丢失怎么办 公司加油卡丢了怎么办 yy频道被回收了怎么办 油卡里的圈存怎么办 农商银行圈存怎么办 社保卡号忘记了怎么办 陕西壳牌加油卡怎么办 联通用超了流量怎么办 联通3g上不了网怎么办 车玻璃水冻住了怎么办 车里玻璃水冻了怎么办 做现货亏了60万怎么办 宿舍太吵晚上睡不着觉怎么办 脚扎了钉子肿了怎么办 龙血树叶子下垂怎么办 龙血树叶子卷曲怎么办 3岁宝宝长期便秘怎么办 4岁小儿便秘严重怎么办 3岁宝宝便秘严重怎么办 3岁宝宝一直便秘怎么办 11个月宝宝便秘怎么办 2个月的宝宝便秘怎么办 宝宝便秘拉不下来怎么办 5一6岁儿童便秘怎么办 3个月宝宝便秘怎么办 8个月宝宝便秘怎么办 孕5个月咳嗽厉害怎么办 孕8个月咳嗽厉害怎么办 拆石膏后关节僵硬怎么办 宝宝的小腿不直怎么办