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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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.

 

 

 

 

 

Expert Solution
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
Maximum Flow
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education