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 di−1di−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 si≤j<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.
The first line contains two integers nn and mm (2≤n≤100,1≤m≤n)(2≤n≤100,1≤m≤n) — the number of days and the number of exams.
Each of the following mm lines contains three integers sisi, didi, cici (1≤si<di≤n,1≤ci≤n)(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.
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 (1≤i≤m1≤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.
5 2
1 3 1
1 5 1
1 2 3 0 3
3 2
1 3 1
1 2 1
-1
10 3
4 7 2
1 10 3
8 9 1
2 2 2 1 1 0 4 3 4 4
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] << " " ;
}
}