← 返回 google 的题目列表Russian Doll Envelopes (Maximum Nesting)
类型:online_judge
Russian Doll Envelopes (LC 354)
You are given n envelopes, each represented as (w, h) for width and height.
Envelope A(w1,h1) can fit into B(w2,h2) iff:
w1 < w2
h1 < h2
Return the maximum number of envelopes you can nest (the length of the longest nesting chain).
Input (stdin)
The first line contains an integer n. The next n lines each contain two integers w h.
Output (stdout)
Print a single integer: the maximum nesting count.
Constraints
1 <= n <= 2 * 10^5
1 <= w, h <= 10^9
Note
You must handle envelopes with the same width correctly so they are not incorrectly counted in the same increasing chain.
Examples
Example
Input
4
5 4
6 4
6 7
2 3
Output
3