You have two arrays and of length . Initially for each integer , .
Now, you are given another array of length and you are asked to count the number of segments in array where array completely overlaps. More formally, array will completely overlap along with a segment of array if there is a segment in array where, and .
Before start counting you can do an operation as many times as you wish to maximize the number of segments where array completely overlaps. The operation is –
The first line contains an integer – number of test cases.
Each test case contains four lines.
The first line of each test case contains an integer .
Next line contains integers .
Next line contains an integer .
The last line of each test case contains integers .
The maximum number of segments in array where array completely overlaps.
2 4 2 3 2 3 2 6 6 6 2 3 5 2 5 2 3 10 15 10
For 1st test case —
After performing the operations, .
So, there are three segments and in array where array completely
overlaps. No other construction can make more than three segments.
Login to submit
First of all, think when will an element of BBB will match with an element of CCC? An element CiC_iC...