Submit | All submissions | Best solutions | Back to list |
HFLY - Airplane Parking |
Because of the limitation of the parking lot, it is not possible to accommodate all requests for parking. Each request consists of the planned arrival time and planned departure time, which are the times the airplane arrives at the parking lot. An example below shows a request table for 4 planes.
Airplane | Arrival | Departure |
1 | 1 | 10 |
2 | 2 | 5 |
3 | 3 | 7 |
4 | 6 | 9 |
In this case, it is possible to accommodate airplane 1, 2, and 4. But it is not possible to accommodate both airplanes 2 and 3.
It is possible that different planes plan to arrive or depart the parking lot at the same time. Jack has the best crews working with him, so that they will manage to arrange the plane to the parking lot in the best way that if it is possible to park and take out the planes they will be able to do it. Consider another example.
Airplane | Arrival | Departure |
5 | 10 | 12 |
6 | 10 | 15 |
7 | 13 | 17 |
Although airplane 5 and 6 arrive at the same time, Jack's crews know that airplane 5 will have to be out before airplane 6, so when both airplanes arrive they put airplane 6 in first, following by airplane 5.
Given a list of parking requests, you want to find the maximum number of airplanes that can be parked in this parking lot, provided that they can only depart in the Last-In First-Out fashion.
Input
The first line contains an integer T, the number of test cases (1 ≤ T ≤ 5). Each test case is in the following format.
The first line starts with an integer N (1 ≤ N ≤ 300) denoting the number of airplanes. The next N lines describe the request table. Each line 1 + i, for 1 ≤ i ≤ N, contains two integer Si and Ti, (0 ≤ Si < Ti ≤ 1,000,000,000) which are the planned arrival time and planned departing time for airplane i.
Output
For each test case, you program must output a single line consisting of one integer, the maximum number of airplanes that can be parked in Jack's parking lot.
Example
Input:
2
4
1 10
2 5
3 7
6 9
3
10 12
10 15
13 17
Output:
3
2
Added by: | DVH |
Date: | 2013-12-06 |
Time limit: | 3s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 |
Resource: | ACM Asia - Phuket - 2009/2010 |
hide comments
2019-10-14 21:54:21 Simes
Exactly the same as PKA |
|
2014-02-22 19:43:08 anon
is first come first server is defined here ? |
|
2013-12-12 14:33:42 DVH
I'm sorry about that,i just update the answer and all submissions has been rejudged! Thanks Last edit: 2013-12-12 14:35:38 |
|
2013-12-06 09:30:32 Jacob Plachta
Is the data definitely correct? I tried my solution on the official data file from the contest (5 cases), on which it worked. |