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.

Input

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.

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 (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.

Examples

Input
5 2
1 3 1
1 5 1
Output
1 2 3 0 3 
Input
3 2
1 3 1
1 2 1
Output
-1
Input
10 3
4 7 2
1 10 3
8 9 1
Output
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个考试,

每一个考试有三个参数。

s是考试可以开始准备的日期。

e是考试日期(这一天必须考试,不能准备)

v,这个考试需要多少天。

每一天最多只能做一件事,要么这一天休息,要么准备考试,要么参加考试。

每一个考试必须在考试之前严格的准备了v天才能通过。

请你确定你是否能能过这M个考试,

如果不可以,只需要输出-1

否则输出每一天i是做什么事情,休息是0,考试是m+1,准备是准备的那个考试编号。

思路:

贪心题,

按照每一个考试的考试日期由近到远排序。

然后枚举每一个天,1~n

如果这一天没有被使用,去检查最近1~m哪一个考试在第 i 天准备。

如果可以填就填,这样贪心搞。

细节见代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=;while(b){if(b%)ans=ans*a%MOD;a=a*a%MOD;b/=;}return ans;}
inline void getInt(int* p);
const int maxn=;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
struct node
{
int s;
int e;
int v;
int id;
}a[];
int n,m;
int vis[];
bool cmp(node aa,node bb)
{
return aa.e<bb.e;
}
int main()
{
//freopen("D:\common_text\code_stream\in.txt","r",stdin);
//freopen("D:\common_text\code_stream\out.txt","w",stdout);
gbtb;
cin>>n>>m;
repd(i,,m)
{
cin>>a[i].s>>a[i].e>>a[i].v;
a[i].id=i;
vis[a[i].e]=m+;
}
sort(a+,a++m,cmp);
repd(i,,n)
{
if(vis[i])
{
continue;
}
repd(j,,m)
{
if(!a[j].v)
{
continue;
}
if(a[j].e>i&&a[j].s<=i)
{
vis[i]=a[j].id;
a[j].v--;
break;
}
}
}
repd(i,,m)
{
if(a[i].v)
{
cout<<-<<endl;
return ;
}
}
repd(i,,n)
{
cout<<vis[i]<<" ";
}
cout<<endl; return ;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}

Codeforces Round #481 (Div. 3)Petya's Exams CodeForces - 978G的更多相关文章

  1. Codeforces Round #481 (Div. 3)

    我实在是因为无聊至极来写Div3题解 感觉我主要的作用也就是翻译一下题目 第一次线上打CF的比赛,手速很重要. 这次由于所有题目都是1A,所以罚时还可以. 下面开始讲题 A.Remove Duplic ...

  2. Codeforces Round #481 (Div. 3) G. Petya's Exams

    http://codeforces.com/contest/978/problem/G 感冒是真的受不了...敲代码都没力气... 题目大意: 期末复习周,一共持续n天,有m场考试 每场考试有如下信息 ...

  3. Codeforces Round #481 (Div. 3) G. Petya's Exams (贪心,模拟)

    题意:你有\(n\)天的时间,这段时间中你有\(m\)长考试,\(s\)表示宣布考试的日期,\(d\)表示考试的时间,\(c\)表示需要准备时间,如果你不能准备好所有考试,输出\(-1\),否则输出你 ...

  4. Codeforces Round #481 (Div. 3)题解

    成功掉到灰,真的心太累了,orz!!!!,不是很懂那些国外大佬为什么每次都是20多分钟AK的,QAQ A. Remove Duplicates time limit per test 1 second ...

  5. Codeforces Round #481 (Div. 3) D. Almost Arithmetic Progression

    http://codeforces.com/contest/978/problem/D 题目大意: 给你一个长度为n的b(i)数组,你有如下操作: 对数组中的某个元素+1,+0,-1.并且这个元素只能 ...

  6. Codeforces Round #481 (Div. 3) 全题解

    A题,题目链接:http://codeforces.com/contest/978/problem/A 解题心得:题意就是让你将这个数列去重,重复的数只保留最右边的那个,最后按顺序打印数列.set+m ...

  7. Codeforces Round #481 (Div. 3) C. Letters

    题目地址:http://codeforces.com/contest/978/problem/C 题解:有n个宿舍,每个宿舍人不一样多,有m封信,每封信送给对应的第m间房间,问这封信是给第几个宿舍,第 ...

  8. Codeforces Round #481 (Div. 3) B. File Name

    题目地址:http://codeforces.com/contest/978/problem/B 题解:一串文件名里不能出现连续的xxx,询问进行几次操作后,文件名才不会出现xxx. 方法:只要遍历一 ...

  9. Codeforces Round #481 (Div. 3) A. Remove Duplicates

    题目地址:http://codeforces.com/contest/978/problem/A 题解:给一串长度为n的数组,然后删去相同的数字(从右往左). 方法:题目n和数组ai给的范围都很小,所 ...

随机推荐

  1. 【MM系列】SAP里批量设置采购信息记录删除标记

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP里批量设置采购信息记录删除标记 ...

  2. 归并排序python实现

    归并排序python实现 归并排序 归并排序在于把序列拆分再合并起来,使用分治法来实现,这就意味这要构造递归算法 首先是一个例子 原序先通过一半一半的拆分,然后: 然后再一步一步的向上合并,在合并的过 ...

  3. 16.Python网络爬虫之Scrapy框架(CrawlSpider)

    引入 提问:如果想要通过爬虫程序去爬取”糗百“全站数据新闻数据的话,有几种实现方法? 方法一:基于Scrapy框架中的Spider的递归爬取进行实现(Request模块递归回调parse方法). 方法 ...

  4. Servlet工作原理解析(tomcat7、嵌入式服务器)

      目录 Servlet 容器Tomcat Servlet 容器的启动过程 Web 应用的初始化工作 Servlet 体系结构 创建 Servlet 对象(如何被加载) 初始化 Servlet(如何被 ...

  5. C#编程の模板

    C#泛型编程已经深入人心了.为什么又提出C#模板编程呢?因为C#泛型存在一些局限性,突破这些局限性,需要使用C#方式的模板编程.由于C#语法.编译器.IDE限制,C#模板编程没有C++模板编程使用方便 ...

  6. ubantu下装Docker

    Docker 要求 Ubuntu 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的 Ubuntu 版本是否支持 Docker. 通过 uname -r 命令查看你当前的内核版本 unam ...

  7. BuildTools Overview

    SCons Pros: Based on a full-fledged programming language, Python. This means you can make the build ...

  8. selenium中遇到div弹框,一起引申到其他弹框

    1.div弹框和DOM普通元素一样处理 2.出现一下就自动消失的弹框,也是在DOM中有描述的,可以使用xpath,用其内容定位 3.(转,其他弹框处理,包括alert和不同windows) https ...

  9. Mac定时关机、重启、休眠命令行

    由于一些原因,需要在不上班的时间去连公司电脑来做一些事.所以公司电脑很少关机.但是在没多天没有关机以后电脑会变得很卡.所以现在每天早上去公司的第一件事情就是先重启一下电脑.人工重启,太不符合程序员的作 ...

  10. 初学Python——文件操作第二篇

    前言:为什么需要第二篇文件操作?因为第一篇的知识根本不足以支撑基本的需求.下面来一一分析. 一.Python文件操作的特点 首先来类比一下,作为高级编程语言的始祖,C语言如何对文件进行操作? 字符(串 ...