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.
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 4 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)