forked from venkatrn/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
/
busyman.cpp
54 lines (50 loc) · 842 Bytes
/
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
53
#include <cstdio>
#include <set>
#include <vector>
using namespace std;
struct comp
{
bool operator()(const pair<int,int>& p1, const pair<int,int>& p2)
{
return p1.second <= p2.second;
}
};
int main()
{
int t,N,a,b;
scanf("%d",&t);
while(t--)
{
set<pair<int,int>,comp> act;
scanf("%d",&N);
for(int i=0;i<N;i++)
{
scanf("%d %d",&a,&b);
act.insert(make_pair(a,b));
}
multiset<pair<int,int>,comp>::iterator it = act.begin();
if(act.size()==0)
{
printf("%d\n",0);
continue;
}
/*
for(;it!=act.end();it++)
{
printf("%d %d\n",it->first,it->second);
}
it = act.begin();
*/
int end_time = it->second;
int activities = 1;
it++;
for(;it!=act.end();it++)
if(it->first>=end_time)
{
end_time = it->second;
activities++;
}
printf("%d\n",activities);
}
return 0;
}