Codeforces Round #481 (Div. 3)Petya's Exams CodeForces - 978G
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
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
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的更多相关文章
- Codeforces Round #481 (Div. 3)
我实在是因为无聊至极来写Div3题解 感觉我主要的作用也就是翻译一下题目 第一次线上打CF的比赛,手速很重要. 这次由于所有题目都是1A,所以罚时还可以. 下面开始讲题 A.Remove Duplic ...
- Codeforces Round #481 (Div. 3) G. Petya's Exams
http://codeforces.com/contest/978/problem/G 感冒是真的受不了...敲代码都没力气... 题目大意: 期末复习周,一共持续n天,有m场考试 每场考试有如下信息 ...
- Codeforces Round #481 (Div. 3) G. Petya's Exams (贪心,模拟)
题意:你有\(n\)天的时间,这段时间中你有\(m\)长考试,\(s\)表示宣布考试的日期,\(d\)表示考试的时间,\(c\)表示需要准备时间,如果你不能准备好所有考试,输出\(-1\),否则输出你 ...
- Codeforces Round #481 (Div. 3)题解
成功掉到灰,真的心太累了,orz!!!!,不是很懂那些国外大佬为什么每次都是20多分钟AK的,QAQ A. Remove Duplicates time limit per test 1 second ...
- Codeforces Round #481 (Div. 3) D. Almost Arithmetic Progression
http://codeforces.com/contest/978/problem/D 题目大意: 给你一个长度为n的b(i)数组,你有如下操作: 对数组中的某个元素+1,+0,-1.并且这个元素只能 ...
- Codeforces Round #481 (Div. 3) 全题解
A题,题目链接:http://codeforces.com/contest/978/problem/A 解题心得:题意就是让你将这个数列去重,重复的数只保留最右边的那个,最后按顺序打印数列.set+m ...
- Codeforces Round #481 (Div. 3) C. Letters
题目地址:http://codeforces.com/contest/978/problem/C 题解:有n个宿舍,每个宿舍人不一样多,有m封信,每封信送给对应的第m间房间,问这封信是给第几个宿舍,第 ...
- Codeforces Round #481 (Div. 3) B. File Name
题目地址:http://codeforces.com/contest/978/problem/B 题解:一串文件名里不能出现连续的xxx,询问进行几次操作后,文件名才不会出现xxx. 方法:只要遍历一 ...
- Codeforces Round #481 (Div. 3) A. Remove Duplicates
题目地址:http://codeforces.com/contest/978/problem/A 题解:给一串长度为n的数组,然后删去相同的数字(从右往左). 方法:题目n和数组ai给的范围都很小,所 ...
随机推荐
- python第一百零八天---Django 3 session 操作
上节内容回顾: 1.请求周期 url> 路由 > 函数或类 > 返回字符串或者模板语言? Form表单提交: 提交 -> url > 函数或类中的方法 - .... Ht ...
- LeetCode算法题-Remove Duplicates from Sorted List
这是悦乐书的第160次更新,第162篇原创 01 前情回顾 昨晚的爬楼梯算法题,有位朋友提了个思路,使用动态规划算法.介于篇幅问题,这里不细说动态规划算法,以后会在数据机构和算法的理论知识里细说. 昨 ...
- 17秋 软件工程 团队第五次作业 Alpha
题目:团队作业--Alpha冲刺 17秋 软件工程 团队第五次作业 Alpha 12次Scrum 第一次Scrum 第二次Scrum 第三次Scrum 第四次Scrum 第五次Scrum 第六次Scr ...
- Angular中ui-router实现路由嵌套案例
学习 ui-router 资料整理 对于Angular内置的路由是单路由视图,ui-router可以实现路由嵌套.后面将会有一个案例概括前面所有资料整理 学习 ui-router - 管理状态 ht ...
- Linux 基本操作 (day2)
一.用户的基本操作 1.添加和删除用户(管理员): useradd 用户名: useradd taibai passwd 用户名: passwd taibai [root@localhost ~] ...
- 设计模式のBuilderPattern(创建者模式)----创建模式
一.产生背景 要组装一台电脑,它的组装过程基本是不变的,都可以由主板.CPU.内存等按照某个稳定方式组合而成.然而主板.CPU.内存等零件本身都是可能多变的.将内存等这种易变的零件与电脑的其他部件分离 ...
- git pull request 流程
git pull request 用于在 fork 官方 repo 到个人 github, 在本地修改后,向官方 repo 请求合并.在官方团队审查过代码后,就可以将自己所做的改动合并到官方 repo ...
- 【转】TCP和SOCKET关系
socket是TCP/IP协议的API TCP是数据的介质,Socket是TCP的介质. 查了一下RFC文档,Socket是RFC147,更新时间是1971年.TCP是RFC793,更新时间是19 ...
- Topshelf:一款非常好用的 Windows 服务开发框架 转发https://www.cnblogs.com/happyframework/p/3601995.html
背景 多数系统都会涉及到“后台服务”的开发,一般是为了调度一些自动执行的任务或从队列中消费一些消息,开发 windows service 有一点不爽的是:调试麻烦,当然你还需要知道 windows s ...
- docker 13 dockerfile的保留字指令
Dockerfile是用来构建Docker镜像的构建文件,是由一系列命令和参数构成的脚本. 构建三步骤:1.编写dockerfile文件:2.docker build:3.docker run doc ...