Interview
InterviewTime limit2sMemory limit1024 MB
Given two sequences a and b, find the length of the longest subsequence of a that is strictly increasing and also a subsequence of b.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Array
- Solved
- No attempts yet
Problem
At the job interview at Sasnart, the candidate solves the longest common increasing subsequence problem for two sequences.
From the sequence , pick a subsequence that satisfies all of the following.
- It is increasing. That is, for every .
- It is a subsequence of .
- Its length is not less than the length of any sequence that satisfies the two conditions above.
Input
The first line contains two integers and (), the lengths of the sequences and . The second line contains the natural numbers of , and the third line contains the natural numbers of . Each number does not exceed 10,000.
Output
Print a single integer, the length of the longest sequence that has the properties described above.