把所有拿钥匙还钥匙的操作和时间都保存在一个优先队列里,按时间先后排序
再用一个数组模拟钥匙盒,按顺序把队列里的操作过一遍,最后输出钥匙盒情况
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
struct node
{
int id;
int sta;
int t;
bool operator < (const node &u) const
{
if(t>u.t) return true;
if(t<u.t) return false;
if(sta>u.sta) return true;
if(sta<u.sta) return false;
if(id>u.id) return true;
return false;
}
};
priority_queue<node> q;
int a[1001];
int main()
{
int n,k,w,s,c;
scanf("%d%d",&n,&k);
node x;
while(k--)
{
scanf("%d%d%d",&w,&s,&c);
x.id=w;
x.sta=1;
x.t=s;
q.push(x);
x.sta=0;
x.t=s+c;
q.push(x);
}
for(int i=0;i<=n;i++)
a[i]=i;
while(!q.empty())
{
x=q.top();
q.pop();
if(x.sta==0)
{
fo