BUSYMAN - I AM VERY BUSY

I AM VERY BUSY

You are actually very busy man. You have a big schedule of activities. Your aim is to do as much as activities as possible.

In the given figure, if you go to date with crush, you cannot participate in the coding contest and you can’t watch the movie. Also if you play DotA, you can’t study for the exam. If you study for the exam you can’t sleep peacefully. The maximum number of activities that you can do for this schedule is 3. 

Either you can

  • watch movie, play DotA and sleep peacefully (or)
  • date with crush, play DotA and sleep peacefully

Input Specifications

The first line consists of an integer T, the number of test cases. For each test case the first line consists of an integer N, the number of activities. Then the next N lines contains two integers m and n, the start and end time of each activity.

Output Specifications

For each test case find the maximum number of activities that you can do.

Input Constraints

1 <= T <=10
1 <= N <= 100000
0 <= start < end <= 1000000

Example

Sample Input: (empty lines just for clarity)
3
3
3 9
2 8
6 9

4
1 7
5 8
7 8
1 8

6
7 9
0 10
4 5
8 9
4 10
5 7

Sample Output:
1
2
3

Added by:cegprakash
Date:2012-05-11
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64

hide comments
2016-01-20 09:13:27
stl->[spoiler]->AC->:)

Last edit: 2016-07-29 22:14:23
2015-11-27 07:59:12
Nice Problem To Learn [spoiler removed] AC in 1 go

Last edit: 2016-04-04 15:01:43
2015-11-11 13:34:12 Ravi
read [spoiler removed] for this question

Last edit: 2016-04-04 15:02:21
2015-10-29 13:09:29
stl :-)

Last edit: 2015-10-29 13:10:59
2015-10-06 21:07:17 jarvis
Cormen & STL good for begineers :)
AC in one go :)

Last edit: 2015-10-06 21:07:39
2015-09-12 09:46:49
learned pairs finally.. all thanks to @rishabh for helping me out
2015-08-24 19:21:08 Babu
Thanks to STL...!! good [spoiler removed] qs for newbies

Last edit: 2016-04-04 15:03:09
2015-07-28 07:07:33 Dikshant Gupta
[spoiler removed]

Last edit: 2015-08-10 20:24:27
2015-06-12 08:23:03 [Mayank Pratap]
Finally AC:)

Last edit: 2015-06-12 08:23:20
2015-06-04 08:18:17 harshit sharma
good question to learn pairs.. :)
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.