-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11000_강의실배정.cpp
56 lines (44 loc) · 1001 Bytes
/
11000_강의실배정.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
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
using namespace std;
int N;
vector<pair<int, int>> list;
bool cmp_list(pair<int, int> x, pair<int, int>y) {
//first 작은 순, second 작은 순
if (x.first == y.first) {
return x.second < y.second;
}
else return x.first < y.first;
}
struct cmp_pq { //아마 작은게 위로 오게 (top에 끝나는 시간이 작은게 나오도록)
bool operator()(pair<int, int>x, pair<int, int>y) {
return x.second > y.second;
}
};
int main() {
cin >> N;
int s, t;
for (int i = 0; i < N; i++) {
cin >> s >> t;
list.push_back({ s,t });
}
sort(list.begin(), list.end(), cmp_list);
//이부분 확인해야함
priority_queue<pair<int, int>, vector<pair<int, int>>, cmp_pq> pq;
pq.push(list[0]);
for (int i = 1; i < list.size(); i++) {
if (list[i].first >= pq.top().second) {
pq.pop();
pq.push(list[i]);
}
else {
pq.push(list[i]);
}
}
int ans = pq.size();
cout << ans;
}