-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1931.cpp
More file actions
38 lines (34 loc) · 730 Bytes
/
1931.cpp
File metadata and controls
38 lines (34 loc) · 730 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
38
#include <bits/stdc++.h>
#define SETTING ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std ;
pair<int,int> arr[100001] ;
int N, answer ;
bool comp(const pair<int,int> &a, const pair<int,int> &b)
{
return a.second == b.second ? a.first < b.first : a.second < b.second ;
}
void FindAnswer()
{
int curr = 0 ;
for(int i = 1 ; i <= N ; i++)
{
if(curr <= arr[i].first)
{
answer++ ; curr = arr[i].second ;
}
}
}
void InputSetting()
{
cin >> N ;
for(int i = 1 ; i <= N ; i++)
cin >> arr[i].first >> arr[i].second ;
}
int main()
{
SETTING ;
InputSetting() ;
sort(&arr[1], &arr[N+1], comp) ;
FindAnswer() ;
cout << answer ;
}