-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path23740.cpp
More file actions
51 lines (46 loc) · 1.15 KB
/
23740.cpp
File metadata and controls
51 lines (46 loc) · 1.15 KB
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
#include <bits/stdc++.h>
#define SETTING ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
using namespace std ;
vector <pair <pair <int, int>, int> > bus_stop, answer ;
int N, S, E, C, idx ;
void InputSetting()
{
cin >> N ;
for(int i = 0 ; i < N ; i++)
{
cin >> S >> E >> C ;
bus_stop.push_back({{S, E}, C});
}
sort(bus_stop.begin(), bus_stop.end()) ;
}
void MakeAnswer()
{
S = bus_stop[0].first.first, E = bus_stop[0].first.second, C = bus_stop[0].second ;
for(int i = 0 ; i < N ; i++)
{
if(bus_stop[i].first.first <= E)
{
E = max(E, bus_stop[i].first.second), C = min(C, bus_stop[i].second) ;
}
else
{
answer.push_back({{S, E}, C}) ;
S = bus_stop[i].first.first, E = bus_stop[i].first.second, C = bus_stop[i].second ;
}
}
answer.push_back({{S, E}, C}) ;
}
void PrintAnswer()
{
cout << answer.size() << endl ;
for(auto it : answer)
cout << it.first.first << " " << it.first.second << " " << it.second << endl ;
}
int main()
{
SETTING ;
InputSetting() ;
MakeAnswer() ;
PrintAnswer() ;
}