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
2018-08-28 13:43:31
it is not as simple as it looks if you are first time encountering such problem, costed 2 WA before AC :(

Last edit: 2018-08-28 13:44:28
2018-08-27 20:23:16


Last edit: 2018-08-27 20:23:30
2018-08-05 22:06:47
Got AC.. But most importantly learnt the problem with Python. The same implementation in Python using the library function took >28M memory and got TLE.
Whereas C++ glided through the test cases like knife through the butter.
If anyone can get AC with Python please let me know. I am interested to learn about your approach. :)
2018-08-02 02:54:04
Can anyone help me, I'm getting TLE error. <snip>

Last edit: 2022-09-05 16:47:31
2018-03-27 09:46:21
[spoiler]

Last edit: 2018-08-22 15:56:09
2018-03-13 19:24:56
dont even look at the graph given in the question. Its just there to explain the question and has nothing to do with the test cases. Confused me a lot
2018-01-03 07:33:33
Perfect schedule :D
2017-12-05 08:23:38
I have used simple [spoiler] and BufferedReader for taking inputs....dont know why I'm getting TLE...Someone Please Help!

Last edit: 2018-01-09 20:55:16
2017-10-20 14:24:38
this was a nice problem and it is "simple" ad-hoc..................................if u know what to do!!!!!!!!!!
do whatever but never miss u'r date
2017-10-15 14:02:42
Typical [spoiler]!!

Last edit: 2018-01-09 20:55:48
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.