spoj#LPERMUT. Longest Permutation
Longest Permutation
You are given a sequence A of n integer numbers (1<=Ai<=n). A subsequence of A has the form Au, Au+1 ... , Av (1<=u<=v<=n). We are interested in subsequences that are permutations of 1, 2, .., k (k is the length of the subsequence).
Your task is to find the longest subsequence of this type.
Input
- Line 1: n (1<=n<=100000)
- Line 2: n numbers A1, A2, ... ,An (1<=Ai<=n)
Output
A single integer that is the length of the longest permutation
Example
Input: 5 4 1 3 1 2 Output: 3