BYTESE2 - The Great Ball
Hogwarts has organized The Great Ball to welcome the schools participating in the Triwizard Tournament. The ball is being held in the Great Hall and The Weird Sisters have been called to play the band. The students drift in to dance and then go out when they get tired. Hagrid is stationed at the gate and is noting down the time at which people enter and leave the hall. At the end of the day, he wonders what the maximum number of dancers was during the course of the ball.
For convenience, he writes down for each person entering, the number of minutes from the start of the ball at which the person entered and left. The door of the hall is narrow, so at any time, either one person can enter or one person can exit, but not both.
For example, suppose the observations noted down by Hagrid are the following:
Serial Number | Enters at | Leaves at |
1 | 1 | 7 |
2 | 2 | 4 |
3 | 6 | 9 |
4 | 3 | 8 |
5 | 5 | 10 |
Each line denotes the entry time and exit time of one person. (The identity of the person is not important - the same person may enter and leave many times. For instance, in the example, it might well be that the entries and exits recorded at serial number 2 and 5 refer to the same person).
In this example, the maximum size of the dancers during the ball was 4. This was achieved between time 6 and 7. Hagrid is not good at Math so he requires your help. Your task is to read the list of entry and exit times and compute the maximum number of dancers during the ball.
Input
The first line is a single integer, T (1<=T<=100), which is the number of test cases. For each of the test case, the first line contains a single integer N, (1<=N<=100), the number of entries and exits recorded. This is followed by N lines. Each of these lines consists of two integers, separated by a space, describing the entry and exit time of that person. The entry and exit times are guaranteed to be distinct, and the entry time will be less than the exit time. The constraint on entry and exit times is 10000000.
Output
A total of T lines each of them containing a single integer, denoting the maximum number of dancers during the ball.
Example
Input: 1 5 1 7 2 4 6 9 3 8 5 10 Output: 4
hide comments
vunnamtej:
2017-03-05 07:52:21
a bit logic! sorting entries and exits and linear traversal 0s Last edit: 2017-03-05 07:53:46 |
|
harshith:
2017-01-26 11:10:15
In the test case given, all the 5 dancers are present in the interval 1-7, so the answer should be 5 rite? Can someone correct me if I am wrong.. |
|
vengatesh15:
2017-01-21 10:56:33
my 150th... |
|
strangerx:
2017-01-20 20:47:48
Topic : Sweep Line |
|
Gaurav Kumar:
2016-12-28 07:22:43
You really do not need STL for this one in C++. Those who are saying are overthinking the problem. Last edit: 2016-12-28 07:23:09 |
|
surajmall:
2016-10-17 21:33:41
easy by STL n C++ Last edit: 2016-12-25 09:06:47 |
|
rraj001:
2016-09-03 12:07:27
good one on stl:)
|
|
sieunhanbom04:
2016-08-19 19:27:10
number compression + BIT? |
|
sharath_111:
2016-08-02 20:32:02
can be done using arrays :)
|
|
shubiks:
2016-07-09 21:54:26
Used sets! :D
|
Added by: | Paritosh Aggarwal |
Date: | 2009-02-21 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | ADA95 ASM32 BASH BF C CSHARP CPP C99 CLPS LISP sbcl LISP clisp D FORTRAN HASK ICON ICK JAVA LUA NEM NICE OCAML PAS-GPC PAS-FPC PERL PHP PIKE PRLG-swi PYTHON RUBY SCM guile SCM qobi ST WHITESPACE |