# CCF201709-2 public key box

Keywords: CCF

Title: public key box
Problem description

In one school, teachers share N classrooms. According to the regulations, all keys must be placed in the public key box. Teachers cannot take keys home. Every time before class, the teacher finds the key of his classroom from the public key box to open the door. After class, he puts the key back in the key box.
The key box has n hooks in a row from left to right, which are used to hang the keys of N classrooms. There is no fixed hanging position for a bunch of keys, but there is a sign on the keys, so teachers won't confuse the keys.
Every time they take the key, the teachers will find the key they need and take it away without moving other keys. Every time you return the key, the teacher who returns the key will find the empty hook on the far left and hang the key on the hook. If more than one teacher returns the key, they return it in the order of key number from small to large. If both teachers return the key and take the key at the same time, the teachers will return all the keys first and then take them out.
At the beginning of today, the keys were placed in the key box in the order of number from small to large. There are K teachers to attend class. Give the keys required by each teacher, the time to start class and the length of class. Assuming that the time after class is the time to return the keys, what is the order of the keys in the final key box?

Input format

The first line of input contains two integers N, K.
The next K lines are three integers W, s and C in each line, which respectively represent the key number to be used by a teacher, the time to start class and the length of class. There may be multiple teachers using the same key, but the time when teachers use the key will not overlap.
Ensure that the input data meets the input format. You don't have to check the legitimacy of the data.

Output format

Output a line containing N integers separated by a space between adjacent integers to represent the key number hung on each hook in turn.

sample input

5 2
4 3 3
2 2 7

sample output

1 4 3 2 5

Example description

The first teacher used the key of classroom 4 from time 3 and used 3 units of time, so he returned the key at time 6. The second teacher used the key from time 2 and used 7 units of time, so he returned the key at time 9.
The key status after each critical moment is as follows (X indicates empty):
1X345 after time 2;
1X3X5 after time 3;
143X5 after time 6;
14325 after time 9.

sample input

5 7
1 1 14
3 3 12
1 15 12
2 7 20
3 18 12
4 21 19
5 30 9

sample output

1 2 3 5 4

Scale and agreement of evaluation cases

For 30% of the evaluation cases, 1 ≤ N, K ≤ 10, 1 ≤ w ≤ N, 1 ≤ s, c ≤ 30;
For 60% of the evaluation cases, 1 ≤ N, K ≤ 50, 1 ≤ w ≤ N, 1 ≤ s ≤ 300, 1 ≤ c ≤ 50;
For all evaluation cases, 1 ≤ N, K ≤ 1000, 1 ≤ w ≤ N, 1 ≤ s ≤ 10000, 1 ≤ c ≤ 100.

Solution:

```#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
struct te{//teacher
int sta,end,x;//Start time, end time, key number
};
bool cmp1(te x1,te x2){
return x1.sta<x2.sta;
}
bool cmp2(te x1,te x2){
if(x1.end==x2.end) {
return x1.x<x2.x;
}else return x1.end<x2.end;
}
int main(){
int n,k,a,b,c;
int time=10100;
cin>>n>>k;
int key[n+1];
te tea1[k],tea2[k];
for(int i=1;i<=n;i++){
key[i]=i;
}
for(int i=0;i<k;i++){
cin>>a>>b>>c;
tea1[i].x=a;tea1[i].sta=b;tea1[i].end=b+c;
tea2[i].x=a;tea2[i].sta=b;tea2[i].end=b+c;
}
sort(tea1,tea1+k,cmp1);
sort(tea1,tea1+k,cmp2);

for(int i=1;i<=time;i++){
for(int j=0;j<k;j++){//Return the key
if(tea2[j].end==i){
for(int k1=1;k1<=n;k1++){
if(key[k1]==-1){
key[k1]=tea2[j].x;
break;
}
}
}
if(tea2[j].end>i) break;
}
//Take the key
for(int j=0;j<k;j++){
if(tea1[j].sta==i){
for(int k1=1;k1<=n;k1++){
if(key[k1]==tea1[j].x)
{
key[k1]=-1;
break;
}
}
}
if(tea1[j].sta>i) break;
}

}
for(int i=1;i<=n;i++){
cout<<key[i]<<" ";
}
}
```

Posted by ipruthi on Sat, 11 Sep 2021 18:59:15 -0700