Petya coordinated a peculiar birthday celebration. He welcomed n companions and relegated an integer ki to the I-th of them. Presently Petya might want to give a present to every one of them. In the close by shop there are m one of a kind presents accessible, the j-th present expenses cj dollars (1≤c1≤c2≤… ≤cm). It's not permitted to purchase
Correct answer will be upvoted else Multiple Downvoted. Computer science.
Petya coordinated a peculiar birthday celebration. He welcomed n companions and relegated an integer ki to the I-th of them. Presently Petya might want to give a present to every one of them. In the close by shop there are m one of a kind presents accessible, the j-th present expenses cj dollars (1≤c1≤c2≤… ≤cm). It's not permitted to purchase a solitary present more than once.
For the I-th companion Petya can either get them a present j≤ki, which costs cj dollars, or simply give them cki dollars straightforwardly.
Assist Petya with deciding the base all out cost of facilitating his get-together.
Input
The originally input line contains a solitary integer t (1≤t≤103) — the number of experiments.
The main line of each experiment contains two integers n and m (1≤n,m≤3⋅105) — the number of companions, and the number of interesting presents accessible.
The accompanying line contains n integers k1,k2,… ,kn (1≤ki≤m), relegated by Petya to his companions.
The following line contains m integers c1,c2,… ,cm (1≤c1≤c2≤… ≤cm≤109) — the costs of the presents.
It is ensured that amount of qualities n over all experiments doesn't surpass 3⋅105, and the amount of qualities m over all experiments doesn't surpass 3⋅105.
Output
For each experiment output a solitary integer — the base expense of the party.
Step by step
Solved in 4 steps with 1 images