-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1828.cpp
More file actions
47 lines (39 loc) Β· 1.01 KB
/
Copy path1828.cpp
File metadata and controls
47 lines (39 loc) Β· 1.01 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 <vector>
#include <algorithm>
using namespace std;
bool cmp(pair<int, int> a, pair<int, int> b){
return a.first < b.first;
}
int main(void){
ios::sync_with_stdio(false);
cin.tie(0);
int N;
cin>>N;
pair<int, int> arr[101];
for(int i=0; i<N; i++){
int from,to;
cin>>from>>to;
arr[i] = make_pair(from,to);
}
sort(arr, arr+N, cmp);
vector<pair<int, int> > v;
v.push_back(make_pair(arr[0].first, arr[0].second));
int cnt = 1;
for(int i=1; i<N; i++){
bool flag = false;
for(int j=0; j<v.size(); j++){
if(arr[i].first <= v[j].second){
flag = true;
if(v[j].first < arr[i].first) v[j].first = arr[i].first;
if(arr[i].second < v[j].second) v[j].second = arr[i].second;
}
}
if(!flag){
cnt++;
v.push_back(make_pair(arr[i].first, arr[i].second));
}
}
cout<<cnt<<"\n";
return 0;
}