-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_11000.cpp
More file actions
42 lines (28 loc) · 815 Bytes
/
BOJ_11000.cpp
File metadata and controls
42 lines (28 loc) · 815 Bytes
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
#include <bits/stdc++.h>
using namespace std;
// 시간표 목록
vector<pair<int, int>> timetable;
// 종료 시간 priority queue
priority_queue<int, vector<int>, greater<int>> pq;
int greedy(int N) {
pq.push(timetable[0].second); // 시작시간이 가장 빠른 수업의 종료시간을 pq에 push
for (int i = 1; i < N; i++) {
pq.push(timetable[i].second); // i번째 수업의 종료시간을 pq에 insert
// pq에 있는 가장 빠른 종료시간보다 i번째 수업이 늦게 시작하면 한 강의실 사용이 가능하므로 가장 빠른 종료시간 pop
if (pq.top() <= timetable[i].first) {
pq.pop();
}
}
return pq.size();
}
int main() {
int N;
cin >> N;
int start, end;
for (int i = 0; i < N; i++) {
cin >> start >> end;
timetable.push_back(make_pair(start, end));
}
sort(timetable.begin(), timetable.end());
cout << greedy(N) << endl;
}