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

hide comments
iloveaakanksha: 2016-05-28 21:36:05

Story of my Life.

adam widi: 2016-05-23 18:05:06

nice problem, learned a lot about [spoiler] and [spoiler] algorithm... :)

Last edit: 2016-07-29 22:12:54
Akshay Damle: 2016-04-28 22:55:50

Got TLE in Python even with PyPy.. :/ Submitted in C++ for AC

carofe82: 2016-04-24 16:27:48

You can solve it in Python 2 but make sure you choose PyPy, otherwise your solution will time out.

being_mj: 2016-04-20 10:06:48

Learned a lot about [spoilers] :)

Last edit: 2016-07-29 22:47:49
lisbecg: 2016-04-13 22:54:41

AC :)

Last edit: 2016-04-14 00:15:51
do_while: 2016-03-06 14:14:12

Solved it finally!
Learned quite a lot from this question!

Last edit: 2016-03-08 13:23:33
pbd: 2016-02-22 10:10:53

CLRS intro to [spoiler removed]

Last edit: 2016-04-04 15:01:13
Wumbolo: 2016-02-13 15:16:40

"Then the next n lines contains two integers m and n"
>>> that is very misleading!

lakshay_v06: 2016-01-25 15:57:06

Just think a bit.... :) Logic will strike in a while....


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