-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11000.cpp
More file actions
47 lines (37 loc) · 1.06 KB
/
11000.cpp
File metadata and controls
47 lines (37 loc) · 1.06 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
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <queue>
using namespace std;
bool sorting (pair<int, int> p1, pair<int, int> p2) {
if (p1.first == p2.first) return p1.second < p2.second;
else return p1.first < p2.first;
}
struct cmp {
bool operator () (pair<int, int> p1, pair<int, int> p2) {
if (p1.second == p2.second) return p1.first > p2.first;
else return p1.second > p2.second;
}
};
int main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int n; cin >> n;
pair<int, int> classtime[200000];
int s, t;
for (int i = 0; i < n; i++) {
cin >> s >> t;
classtime[i] = make_pair(s, t);
}
sort(classtime, classtime + n, sorting);
priority_queue<pair<int, int>, vector< pair<int, int> >, cmp> pq;
for (int i = 0; i < n; i++) {
if (!pq.empty() && pq.top().second <= classtime[i].first)
pq.pop();
pq.push(classtime[i]);
}
cout << pq.size();
return 0;
}