Boardroom Meeting
Time limit10sMemory limit512 MB
Pick the largest set of days, in order, where both companies' prices strictly increase across the chosen days.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Divide and conquer, Sorting
- Solved
- No attempts yet
Problem
Recently, you have been hired by an investment fund. You quickly developed a feeling that something here was amiss, especially when a client's money has been invested in two companies carefully selected by their best astrologist.
Unfortunately, for the last days the stock prices were (mostly) falling. The boss called an urgent meeting.
"Ladies and gentlemen, you all know the situation. Any ideas?" The boss had a nice habit of getting straight to the point, even when that point apparently lay in another dimension of reality.
"We can choose a good subset of days, so that the prices are only increasing, then show the client only that company's prices for these days!" volunteered Billy, the last Employee of the Month.
"We can do better! Select the days such that both companies' prices form an increasing sequence!" Anna, the senior manager, would not allow herself to stay behind.
"How about ditching the astrologist and doing some serious research?" The words came from you almost involuntarily, as if your brain and vocal cords had fired without your consent.
The boss looked at you. It was not exactly a look of earnest approval.

Now you have some bruises, a lot of stairs to climb, and much work to do. Given the stock prices of the two companies for consecutive days, find the maximum subset of days so that both price subsequences are (strictly) increasing. It is enough to output the maximum number of days.
Input
The first line of input contains the number of test cases . The descriptions of the test cases follow.
The first line of every test case contains the number of days (). Then two lines follow. The first one contains positive integers not exceeding , the stock prices of the first company for all days. The second line contains the second company's prices, in the same format.
The total number of days in all test cases does not exceed .
Output
For each test case, print a single integer on its own line: the maximum possible number of days.