题库练习 Strange Birthday Party
← 上一题 下一题 →

A14016 | Strange Birthday Party

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

Petya organized a strange birthday party. He invited $n$ friends and assigned an integer $k_i$ to the $i$ -th of them. Now Petya would like to give a present to each of them. In the nearby shop there are $m$ unique presents available, the $j$ -th present costs $c_j$ dollars ( $1 \le c_1 \le c_2 \le \ldots \le c_m$ ). It's not allowed to buy a single present more than once.

For the $i$ -th friend Petya can either buy them a present $j \le k_i$ , which costs $c_j$ dollars, or just give them $c_{k_i}$ dollars directly.

Help Petya determine the minimum total cost of hosting his party.

输入格式

The first input line contains a single integer $t$ ( $1 \leq t \leq 10^3$ ) — the number of test cases.

The first line of each test case contains two integers $n$ and $m$ ( $1 \leq n, m \leq 3 \cdot 10^5$ ) — the number of friends, and the number of unique presents available.

The following line contains $n$ integers $k_1, k_2, \ldots, k_n$ ( $1 \leq k_i \leq m$ ), assigned by Petya to his friends.

The next line contains $m$ integers $c_1, c_2, \ldots, c_m$ ( $1 \le c_1 \le c_2 \le \ldots \le c_m \le 10^9$ ) — the prices of the presents.

It is guaranteed that sum of values $n$ over all test cases does not exceed $3 \cdot 10^5$ , and the sum of values $m$ over all test cases does not exceed $3 \cdot 10^5$ .

输出格式

For each test case output a single integer — the minimum cost of the party.

输入输出样例

输入 #1
2
5 4
2 3 4 3 2
3 5 12 20
5 5
5 4 3 2 1
10 40 90 160 250
输出 #1
30
190
输入 #2
1
1 1
1
1
输出 #2
1
C++ 编辑器
输入
输出