Muhammadali has an integer array $$$a_1,\dots,a_n$$$. He can change (replace) any subset of positions; changing position $$$i$$$ costs $$$c_i$$$ and replaces $$$a_i$$$ with any integer of his choice. The positions that he does not change must retain their original values.
After all changes, we call an index $$$i$$$ ($$$1 \le i \lt n$$$) a drop if the final value at position $$$i$$$ is strictly greater than the final value at position $$$i+1$$$. Muhammadali wants the final array to contain no drops.
Find the minimum cost of changes required to ensure that there are no drops in the array.
The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) — the number of test cases.
Each test case consists of three lines:
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 8000$$$) — the length of the arrays.
The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array.
The third line contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 10^9$$$) — the costs of changes.
It is guaranteed that the sum of $$$n$$$ across all test cases does not exceed $$$8000$$$.
For each test case, output a single integer — the minimum possible total cost required to eliminate all drops.
10110541 2 2 35 6 7 844 3 2 11 1 1 133 1 2100 1 155 5 5 5 510 1 10 1 1051 3 2 2 4100 1 1 1 100610 9 8 7 6 51 100 1 100 1 1005100 1 100 100 1001 100 1 1 142 1 2 15 4 3 271 5 3 4 2 6 710 1 10 1 10 1 10
0032012031611
In the first and second examples, the array already has no drops, so no changes are needed.
In the third example, one of the optimal arrays is: $$$[2,3,5,6]$$$; to achieve this, all elements except the second need to be replaced, so the answer is $$$c_1 + c_3 + c_4 = 3$$$.