You may reorder the elements of $$$a$$$ arbitrarily. Let $$$b$$$ be the array obtained after reordering. The array $$$w$$$ is not reordered: $$$w_i$$$ always belongs to position $$$i$$$.
A position $$$i$$$ ($$$1 \le i \le n$$$) is called good if $$$b_i \le i$$$. The score of $$$b$$$ is the sum of weights of all good positions. In other words, for every good position $$$i$$$, add $$$w_i$$$ to the score.
Find the maximum possible score.
The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The first line of a test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of the arrays.
The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$).
The third line contains $$$n$$$ integers $$$w_1, w_2, \ldots, w_n$$$ ($$$0 \le w_i \le 10^9$$$).
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, print one integer — the maximum possible score.
2 5 2 4 1 7 2 5 3 9 4 8 4 10 10 10 10 1 2 3 4
26 0
In the first sample, one optimal reordered array is $$$b=[1,7,2,2,4]$$$. Positions $$$1$$$, $$$3$$$, $$$4$$$, and $$$5$$$ are good, so the score is $$$5+9+4+8=26$$$. In the second sample, every element of $$$a$$$ is greater than every valid position index, so no position can be good and the answer is $$$0$$$.
| Название |
|---|


