-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathB.cpp
42 lines (33 loc) · 787 Bytes
/
B.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
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n;
vector<pair<int, int>> time;
bool comp(pair<int, int>& x, pair<int, int>& y) {
return (x.second < y.second);
}
int main() {
freopen("request.in", "r", stdin);
freopen("request.out", "w", stdout);
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int s, f;
scanf("%d %d", &s, &f);
time.emplace_back(make_pair(s, f));
}
sort(time.begin(), time.end(), comp);
int count = 1;
int curtime = time[0].second;
int cur = 0;
while (cur < n) {
if (time[cur].first < curtime) {
cur++;
} else {
count++;
curtime = time[cur].second;
}
}
printf("%d", count);
return 0;
}