-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1931.cpp
More file actions
37 lines (33 loc) · 833 Bytes
/
1931.cpp
File metadata and controls
37 lines (33 loc) · 833 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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n, MAX = 0; // 총 회의 개수, 회의실을 사용할 수 있는 회의 개수
vector<pair<int, int>> board; // (start time, end time)
bool compare(pair<int, int>& a, pair<int, int>& b) {
// second값으로 비교하고 > 만약 second값이 같다면 > first값으로 비교
if (a.second == b.second) return a.first < b.first;
else return a.second < b.second;
}
int greedy() {
int cnt = 1, end = board[0].second;
for (int i = 1; i < n; i++) {
if (end <= board[i].first) {
cnt++;
end = board[i].second;
}
}
MAX = max(MAX, cnt);
return MAX;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
int start, end; cin >> start >> end;
board.push_back(make_pair(start, end));
}
sort(board.begin(), board.end(), compare);
greedy();
cout << MAX;
return 0;
}