-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBUSYMAN.cpp
52 lines (37 loc) · 1.23 KB
/
BUSYMAN.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
// AC, ALGO : Greedy, Activity Selection problem.
/* Some Helpful Links :
http://www.cplusplus.com/reference/utility/pair/
http://en.wikipedia.org/wiki/Activity_selection_problem
http://www.geeksforgeeks.org/greedy-algorithms-set-1-activity-selection-problem/
*/
// For any clarifications, contact me at : osinha6792@gmail.com
#include<cstdio>
#include<utility>
#include<algorithm>
using namespace std ;
int main( )
{
int t , i , s , f , n , ctr , k ;
scanf("%d",&t) ;
pair<int,int> a[100001] ;
while( t-- )
{
scanf("%d",&n) ;
for( i = 0 ; i < n ; i++ )
{
scanf("%d%d",&s,&f) ;
a[i] = make_pair(f,s) ;
}
sort( a , a + n ) ;
for( k = 0 , ctr = i = 1 ; i <= n ; i++ )
{
if( a[i].second >= a[k].first )
{
ctr++ ;
k = i ;
}
}
printf("%d\n",ctr) ;
}
return 0 ;
}