Codeforces 496E. Distributing Parts 排序+贪心


将歌曲按低音从小到大排序,歌手也按低音从小到大排序.

对每首歌曲,在一个SET中查找低音满足条件的而高音刚好满足条件的歌手

E. Distributing Parts
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 chose m 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, ciand di (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 the j-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 most ki 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 and bj — the range of notes for the j-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, cidi and ki — the range of the i-th actor and the number of parts that he can perform (1 ≤ ci ≤ di ≤ 1091 ≤ 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. The i-th integer should be the number of the actor who should perform the i-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).

Sample test(s)
input
3
1 3
2 4
3 5
2
1 4 2
2 5 1
output
YES
1 1 2
input
3
1 3
2 4
3 5
2
1 3 2
2 5 1
output
NO



/* ***********************************************
Author        :CKboss
Created Time  :2015年03月24日 星期二 18时04分40秒
File Name     :CF496E.cpp
************************************************ */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;

typedef pair<int,int> pII;

const int maxn=100100;

int n,m;

struct Part
{
	int l,r,id;
}part[maxn];

struct Actor
{
	int l,r,k,id;
}actor[maxn];

bool cmp1(Part A,Part B)
{
	if(A.l!=B.l) return A.l<B.l;
	return A.r<B.r;
}

bool cmp2(Actor A,Actor B)
{
	if(A.l!=B.l) return A.l<B.l;
	return A.r<B.r;
}

set<pII> SP;

int ans[maxn];
int num[maxn];

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

	scanf("%d",&n);

	for(int i=0;i<n;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		part[i].l=a; part[i].r=b; part[i].id=i;
	}

	scanf("%d",&m);
	for(int i=0;i<m;i++)
	{
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		actor[i].l=a; actor[i].r=b; actor[i].k=c; actor[i].id=i;
		num[i]=c;
	}

	sort(part,part+n,cmp1);
	sort(actor,actor+m,cmp2);

	bool flag=true;
	int nx=0;

	SP.insert(make_pair(1756942789,0));

	for(int i=0;i<n;i++)
	{
		/// add actor
		while(nx<m&&actor[nx].l<=part[i].l)
		{
			SP.insert(make_pair(actor[nx].r,actor[nx].id));
			nx++;
		}
		/// binary search
		pII temp=*(SP.lower_bound(make_pair(part[i].r,0)));
		if(temp.first==1756942789)
		{
			flag=false;
			break;
		}
		ans[part[i].id]=temp.second;
		num[temp.second]--;
		if(num[temp.second]==0) SP.erase(temp);
	}
	
	if(flag==false) puts("NO");
	else
	{
		puts("YES");
		for(int i=0;i<n;i++) printf("%d ",ans[i]+1);
		putchar(10);
	}
    
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值