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,ci and 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 — ajand 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 ≤ 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. 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).

Examples
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

题意:给你n首歌,m个歌手,每首歌和歌手都有最低音和最高音,只有歌手的最低音小于等于歌的最低音并且最高音大于等于歌的最高音才能唱这首歌,问是否能唱完,求唱完后的序列;

思路:排序,插入最低音在这之前的歌手,找到最低 满足的歌手;

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
const int N=1e5+,M=1e6+,inf=1e9+,mod=1e9+;
struct iterval
{
int l,r,pos;
bool operator <(const iterval &b)const
{
if(l!=b.l)
return l<b.l;
return r<b.r;
}
}a[N];
struct is
{
int a,b,k,pos;
bool operator <(const is &x)const
{
if(a!=x.a)
return a<x.a;
return b<x.b;
}
}b[N];
set< pair < pair < int , int > , int> >s;
set< pair < pair < int , int > , int> >::iterator it,itt;
int ans[N];
int main()
{
int n,m;
scanf("%d",&n);
for(int i=;i<n;i++)
scanf("%d%d",&a[i].l,&a[i].r),a[i].pos=i;
sort(a,a+n);
scanf("%d",&m);
for(int i=;i<m;i++)
scanf("%d%d%d",&b[i].a,&b[i].b,&b[i].k),b[i].pos=i;
sort(b,b+m);
int flag=,gg=;
for(int i=;i<n;i++)
{
while(b[flag].a<=a[i].l&&flag<m)
{
s.insert(make_pair(make_pair(b[flag].b,b[flag].k),b[flag].pos));
flag++;
}
it=s.lower_bound(make_pair(make_pair(a[i].r,),));
if(it==s.end())
{
gg=;
break;
}
ans[a[i].pos]=it->second;
pair < pair < int , int > , int> k=*it;
s.erase(it);
if(k.first.second>)
{
k.first.second--;
s.insert(k);
}
}
if(gg)
{
printf("NO\n");
}
else
{
printf("YES\n");
for(int i=;i<n;i++)
printf("%d ",ans[i]+);
}
return ;
}

Codeforces Round #283 (Div. 2) E. Distributing Parts 贪心+set二分的更多相关文章

  1. 暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns

    题目传送门 /* 题意:删除若干行,使得n行字符串成递增排序 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 */ /*********************** ...

  2. 构造+暴力 Codeforces Round #283 (Div. 2) B. Secret Combination

    题目传送门 /* 构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好! */ /************************************** ...

  3. codeforces 497c//Distributing Parts// Codeforces Round #283(Div. 1)

    题意:有n个区间[ai,bi],然后有n个人落在[ci,di],每个人能用ki次.问一种方式站满n个区间. 两种区间都用先x后y的升序排序.对于当前的区间[ai,bi],将ci值小于当前ai的全部放入 ...

  4. Codeforces Round #283 (Div. 2) C. Removing Columns 暴力

    C. Removing Columns time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  5. Codeforces Round #283 (Div. 2) A ,B ,C 暴力,暴力,暴力

    A. Minimum Difficulty time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  6. Codeforces Round #283 Div.2 D Tennis Game --二分

    题意: 两个人比赛,给出比赛序列,如果为1,说明这场1赢,为2则2赢,假如谁先赢 t 盘谁就胜这一轮,谁先赢 s 轮则赢得整个比赛.求有多少种 t 和 s 的分配方案并输出t,s. 解法: 因为要知道 ...

  7. Codeforces Round #283 (Div. 2)

    A:暴力弄就好,怎么方便怎么来. B:我们知道最多加10次, 然后每次加1后我们求能移动的最小值,大概O(N)的效率. #include<bits/stdc++.h> using name ...

  8. codeforces 497b// Tennis Game// Codeforces Round #283(Div. 1)

    题意:网球有一方赢t球算一场,先赢s场的获胜.数列arr(长度为n)记录了每场的胜利者,问可能的t和s. 首先,合法的场景必须: 1两方赢的场数不一样多. 2赢多的一方最后一场必须赢. 3最后一场必须 ...

  9. Codeforces Round #283 (Div. 2) B. Secret Combination 暴力水题

    B. Secret Combination time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

随机推荐

  1. MVC action 执行两次 background url()

    大年初七第一天上班就来解决问题,我也是醉了. 其实是历史遗留问题,今天看到后不能忍了,赶紧解决一下. 旧系统中以一个微信版本的列表页面没有问题,在新系统中重新开发一边后发现列表页面的action总是请 ...

  2. iOS反射:把对象直接转化成NSDictionary

    在IOS的网络编程中,通常我们需要将一些实体数据保存到NSDictionary,在获得NSDictionary后即可直接使用iOS 5后的NSJSONSerialization类型的dataWithJ ...

  3. Cookies with curl the command line tool

    w https://curl.haxx.se/docs/http-cookies.html curl has a full cookie "engine" built in. If ...

  4. diy 重要的不是这个工具怎么解决了问题

    w 0-这个工具解决了什么问题? 1-diy,怎么解决这个工具解决了的问题? 2-是否diy实现?实现了,对比,优化:反之,分析借鉴,吸收优化. 重要的不是git怎样解决了git已经解决的问题.

  5. 在Nuxt中使用 Highcharts

    npm进行highchars的导入,导入完成后就可以进行highchars的可视化组件开发了 npm install highcharts --save 1.components目录下新建一个char ...

  6. python函数回顾:hex()

    描述 hex() 函数用于将10进制整数转换成16进制,以字符串形式表示. 语法 hex 语法: hex(x) 参数说明: x -- 10进制整数 返回值 返回16进制数,以字符串形式表示. 实例 & ...

  7. Python 中星号作用:解包&打散

    python中’*’和’**’的使用分两个方面,一个是计算,另一个是参数传递过程中元素的打包和解包.  计算方面 ‘*’和’**’在python中最常见的作用分别是‘相乘’和‘乘幂’,如下: > ...

  8. Python3.6全栈开发实例[007]

    7.此函数只接收一个参数且此参数必须是列表数据类型,此函数完成的功能是返回给调用者一个字典,此字典的键值对为此列表的索引及对应的元素.例如传入的列表为:[11,22,33] 返回的字典为 {0:11, ...

  9. leetCode 64.Minimum Path Sum (最短路) 解题思路和方法

    Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...

  10. Libsvm在matlab环境下使用指南

    一.安装 http://www.csie.ntu.edu.tw/~cjlin/libsvm/matlab/.在这个地址上可以下的包含matlab接口的源程序.下载完后可以放到放到任意的盘上解压,最好建 ...