in a queue n n soldiers with numbers from 1 to n n are standing. soldier i iam in the…
- User
in a queue n n soldiers with numbers from 1 to n n are standing. soldier i iam in the beginning S i S i He has a merit badge (medal) on his chest.
during a ceremony m The general wants to give these soldiers new medals. We know, General i I am to the soldiers whose numbers are in the range of [ a i , b i ] [a i b i ] will give a medal. We also know that if the intervals of two generals like x x and y y share, two soldiers cannot be like u u and v v found that u u only from x x (and not from y y) and v v only from y y (and not from x x) has received a medal.
The host of the ceremony wants to invite a subset of generals to the ceremony so that at the end of the ceremony (after the medals are awarded), the number of soldiers who have individual medals (including the initial medals) will be maximized. Find this maximum value!
You have to pay in return t t Find the answer scenario.
input In the first line, enter a natural number t t has come.
For each scenario, in the first line n n and in the line after that S i S i are in order.
Then in the next line m m has come; In the next line 2 m 2m number is written as number 2 i
1 2i−1th, a i a i and the number 2 i 2nd is equal b i b i will be
1 ≤ t ≤ 20 1≤t≤20
in general 1 ≤ n , m ≤ 100
000 1≤n, m≤100,000, but in 30% of the tests, it is a condition 1 ≤ n , m ≤ 2
000 1≤n, m≤2000 will be established.
1 ≤ a i ≤ b i ≤ n 1≤a i ≤b i ≤n
All input numbers are correct, non-negative and at most equal 1 0 9 10 9 will be
output Write the answer to each scenario (the maximum number of soldiers with the mentioned conditions) in separate lines.
Sub-issues Constraint score subproblem 100 without additional restrictions Example Sample entry 1 2 3 8 9 0 3 1 3 1 1 1 1 4 7 6 8 2 3 1 4 1 1 4 4 Plain text Sample output 1 2 4
- Assistant