Codeforces 978 G. Petya's Exams(1ni)

G. Petya's Exams
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Petya studies at university. The current academic year finishes with nn special days. Petya needs to pass mm exams in those special days. The special days in this problem are numbered from 11 to nn.

There are three values about each exam:

  • sisi — the day, when questions for the ii-th exam will be published,
  • didi — the day of the ii-th exam (si<disi<di),
  • cici — number of days Petya needs to prepare for the ii-th exam. For the ii-th exam Petya should prepare in days between sisi and di1di−1, inclusive.

There are three types of activities for Petya in each day: to spend a day doing nothing (taking a rest), to spend a day passing exactly one exam or to spend a day preparing for exactly one exam. So he can't pass/prepare for multiple exams in a day. He can't mix his activities in a day. If he is preparing for the ii-th exam in day jj, then sij<disi≤j<di.

It is allowed to have breaks in a preparation to an exam and to alternate preparations for different exams in consecutive days. So preparation for an exam is not required to be done in consecutive days.

Find the schedule for Petya to prepare for all exams and pass them, or report that it is impossible.

Input

The first line contains two integers nn and mm (2n100,1mn)(2≤n≤100,1≤m≤n) — the number of days and the number of exams.

Each of the following mm lines contains three integers sisididicici (1si<din,1cin)(1≤si<di≤n,1≤ci≤n) — the day, when questions for the ii-th exam will be given, the day of the ii-th exam, number of days Petya needs to prepare for the ii-th exam.

Guaranteed, that all the exams will be in different days. Questions for different exams can be given in the same day. It is possible that, in the day of some exam, the questions for other exams are given.

Output

If Petya can not prepare and pass all the exams, print -1. In case of positive answer, print nn integers, where the jj-th number is:

  • (m+1)(m+1), if the jj-th day is a day of some exam (recall that in each day no more than one exam is conducted),
  • zero, if in the jj-th day Petya will have a rest,
  • ii (1im1≤i≤m), if Petya will prepare for the ii-th exam in the day jj (the total number of days Petya prepares for each exam should be strictly equal to the number of days needed to prepare for it).

    Assume that the exams are numbered in order of appearing in the input, starting from 11.

    If there are multiple schedules, print any of them.

Examples
input
Copy
5 2
1 3 1
1 5 1
output
Copy
1 2 3 0 3 
input
Copy
3 2
1 3 1
1 2 1
output
Copy
-1
input
Copy
10 3
4 7 2
1 10 3
8 9 1
output
Copy
2 2 2 1 1 0 4 3 4 4 
Note

In the first example Petya can, for example, prepare for exam 11 in the first day, prepare for exam 22 in the second day, pass exam 11 in the third day, relax in the fourth day, and pass exam 22 in the fifth day. So, he can prepare and pass all exams.

In the second example, there are three days and two exams. So, Petya can prepare in only one day (because in two other days he should pass exams). Then Petya can not prepare and pass all exams.


题目大意:输入 n,m;

a,b,c(表示第a天知道考试,b天要考试,需要c天的时间准备)

思路:任何考试,都是从知道当天开始复习,假如当天没安排,就复习,有安排就跳过,直到考试那一天,假如到考试那一天还没复习完,就输出-1

用一个vis数组记录就好了,但是要对b排序,因为肯定是先考最早的那一天,所以优先排序要考试的那一天,哪天知道不重要,这样就可以AC了


#include<bits/stdc++.h>
using namespace std;
struct node
{
	int a,b,c,d;
}po[105];

int cmp(node a,node b)
{
	return a.b < b.b; 
}
int main()
{
	int n,m;
	cin >> n >> m;
	int vis[105];
	memset(vis,0,sizeof(vis));
	
	for(int i=0;i<m;i++)
	{
		cin >> po[i].a >> po[i].b >> po[i].c;
		po[i].d = i + 1;
		vis[po[i].b] = m+1;
	}
	
	sort(po,po+m,cmp);
	for(int i=0;i<m;i++)
	{
		int num=0;
		for(int j=po[i].a;j<po[i].b;j++)
		{
			if(vis[j]==0)
			{
				vis[j]=po[i].d;
				num++;
			}
			if(num==po[i].c) break;
		}
		if(num!=po[i].c)
		{
			cout << -1 << endl;
			return 0;
		}
	}
	for(int i=1;i<=n;i++)
	{
		cout << vis[i] << " " ;
	}
} 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值