Rectangles Too!
Time limit3sMemory limit128 MB
Find the longest chain of rectangles where each rectangle lies strictly below and to the left of the next one.
- Level
Hard8 of 10
- Topics
- Sorting, Dynamic programming, Segment tree
- Solved
- No attempts yet
Problem
A rectangle in the Cartesian plane is given by two corner points and , its lower-left and upper-right corners, with and .
For two rectangles and , we say that precedes , written , when
You are given a collection of rectangles in the plane. Find the length of the longest sequence of rectangles from the collection such that
Input
The input contains several test cases. Each test case starts with a line containing one integer (), the number of rectangles. Each of the next lines contains four integers ( and ), the lower-left and upper-right corners of one rectangle. The input ends with a line containing a single .
Output
For each test case, print one line with a single integer: the length of the longest chain of rectangles.