-
Notifications
You must be signed in to change notification settings - Fork 1
/
201709-2.cpp
82 lines (79 loc) · 1.71 KB
/
201709-2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "stdio.h"
#include "vector"
#include "algorithm"
struct thing {
int w;
int t;
int borrow_flag;
};
int cmp(thing a, thing b) {
if (a.t > b.t) {
return 0;
}
if (a.t == b.t) {
if (a.borrow_flag == 1 && b.borrow_flag == 0) {
return 0;
}
if (a.borrow_flag == 0 && b.borrow_flag == 1) {
return 1;
}
if (a.w > b.w) {
return 0;
} else {
return 1;
}
}
return 1;
};
int main() {
int N, K;
std::vector<thing> things;
int flag[1000 + 10] = {0};
int pos[1000 + 10];
int w, s, c;
thing th;
scanf("%d%d", &N, &K);
for (int i = 1; i <= N; ++i) {
pos[i] = i;
}
for (int i = 0; i < K; ++i) {
scanf("%d%d%d", &w, &s, &c);
th.w = w;
th.t = s;
th.borrow_flag = 1;
things.push_back(th);
th.w = w;
th.t = s + c;
th.borrow_flag = 0;
things.push_back(th);
}
std::sort(things.begin(), things.end(), cmp);
for (int i = 0; i < things.size(); ++i) {
if (things[i].borrow_flag == 1) {
int j;
for (j = 1; j <= N; ++j) {
if (things[i].w == pos[j]) {
break;
}
}
pos[j] = -1;
flag[j] = 1;
} else {
int j;
for (j = 1; j <= N; ++j) {
if (flag[j] == 1) {
break;
}
}
pos[j] = things[i].w;
flag[j] = 0;
}
}
for (int i = 1; i <= N; ++i) {
printf("%d", pos[i]);
if (i < N) {
printf(" ");
}
}
return 0;
}