LIS2VN - Another Longest Increasing Subsequence Problem

Given a sequence of N pairs of integers, find the length of the longest increasing subsequence of it.

An increasing sequence A1..An is a sequence such that for every i < j, Ai < Aj.

A subsequence of a sequence is a sequence that appears in the same relative order, but not necessarily contiguous.

A pair of integers (x1, y1) is less than (x2, y2) if x1 < x2 and y1 < y2.

Input

The first line of input contains an integer N (2 ≤ N ≤ 100000).

The following N lines consist of N pairs of integers (xi, yi) (-109xi, yi ≤ 109).

Output

The output contains an integer: the length of the longest increasing subsequence of the given sequence.

Example

Input:
8
1 3
3 2
1 1
4 5
6 3
9 9
8 7
7 6

Output:
3

Original problem: http://www.spoj.com/problems/LIS2/.


Được gửi lên bởi:Race with time
Ngày:2009-04-13
Thời gian chạy:1s
Giới hạn mã nguồn:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Ngôn ngữ cho phép:Tất cả ngoại trừ: ERL GOSU JS-RHINO NODEJS PERL6 PYPY RUST SED VB.NET
Nguồn bài:Jin Bin - SPOJ

hide comments
2019-09-24 05:00:12
hahaha bai de :v
duonght_pro_xinhgainhathemattroi_:)
2017-11-13 15:24:26
NlogN toan WA thoi
2017-01-04 15:21:33 John and the cows
Mọi người cho mình hỏi bài này có thuật O(NlogN) không? Nếu có thì cho mình xin tài liệu với.

Last edit: 2017-01-04 15:22:52
2014-12-02 17:57:27 livw
trong day co ton tai 2 cap giong nhau khong nhi?
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.