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


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

1 7
5 8
7 8
1 8

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

Sample Output:

hide comments
akashbhalotia: 2017-08-21 21:39:45

Hey admin, all Java submissions are getting TLE.

babur: 2017-06-26 14:27:30

Agree more than 100% with @abhishek18620...this is a classical question.

robotlaserbeam: 2017-06-15 06:42:20

Has anyone been able to solve this in Java? I am using a buffered reader and a comparator but am still getting time limit exceeded.

steady_bunny: 2017-05-17 14:24:56

Dating Crush would be preferred!! :)

blackjag: 2017-04-18 08:18:33

nice [spoiler]

Last edit: 2017-08-02 13:03:17
abhishek18620: 2017-04-06 14:04:56

Saying 'easy' here doesn't prove anything.. i still can't get why people brag here. As far as this question is concerned it is a beginner's [spoiler] question or u can take it as an ad-hoc too.

Last edit: 2017-08-02 13:03:40
redarrow1711: 2017-03-30 10:16:09


deep_1: 2017-03-18 12:42:19

AC in one go!!!

amulyagaur: 2017-03-16 15:23:47

AC in one go

rohit9934: 2017-03-05 15:50:31

STL pair or Structures in C. MF Spoiler

Last edit: 2017-03-05 15:50:52

Added by:cegprakash
Time limit:0.324s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64