CF1470A.Strange Birthday Party

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Petya organized a strange birthday party. He invited nn friends and assigned an integer kik_i to the ii-th of them. Now Petya would like to give a present to each of them. In the nearby shop there are mm unique presents available, the jj-th present costs cjc_j dollars (1≤c1≤c2≤…≤cm1 \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 ii-th friend Petya can either buy them a present j≤kij \le k_i, which costs cjc_j dollars, or just give them ckic_{k_i} dollars directly.

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

佩佳举办了一场奇特的生日派对。他邀请了 nn 位朋友,并为第 ii 位朋友分配了一个整数 kik_i。现在佩佳希望给每位朋友赠送一份礼物。附近商店里有 mm 种独一无二的礼物可供选择,其中第 jj 种礼物的价格为 cjc_j 美元(满足 1≤c1≤c2≤…≤cm1 \le c_1 \le c_2 \le \ldots \le c_m)。每种礼物最多只能购买一次。

对于第 ii 位朋友,佩佳有两种选择:

  • 购买一件编号 j≤kij \le k_i 的礼物(花费 cjc_j 美元),
  • 或者直接给予其 ckic_{k_i} 美元现金。

请帮助佩佳计算举办这场派对所需的最小总花费。

输入格式

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

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

The following line contains nn integers k1,k2,…,knk_1, k_2, \ldots, k_n (1≤ki≤m1 \leq k_i \leq m), assigned by Petya to his friends.

The next line contains mm integers c1,c2,…,cmc_1, c_2, \ldots, c_m (1≤c1≤c2≤…≤cm≤1091 \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 nn over all test cases does not exceed 3⋅1053 \cdot 10^5, and the sum of values mm over all test cases does not exceed 3⋅1053 \cdot 10^5.

第一行输入包含一个整数 tt(1≤t≤1031 \leq t \leq 10^3),表示测试用例的数量。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n,m≤3⋅1051 \leq n, m \leq 3 \cdot 10^5),分别表示朋友的数量和可选礼物的种类数。

接下来一行包含 nn 个整数 k1,k2,…,knk_1, k_2, \ldots, k_n(1≤ki≤m1 \leq k_i \leq m),表示 Petya 分配给各位朋友的礼物编号。

下一行包含 mm 个整数 c1,c2,…,cmc_1, c_2, \ldots, c_m(1≤c1≤c2≤…≤cm≤1091 \le c_1 \le c_2 \le \ldots \le c_m \le 10^9),表示各礼物的价格。

保证所有测试用例中 nn 的总和不超过 3⋅1053 \cdot 10^5,且所有测试用例中 mm 的总和也不超过 3⋅1053 \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

说明/提示

In the first example, there are two test cases. In the first one, Petya has 55 friends and 44 available presents. Petya can spend only 3030 dollars if he gives

  • 55 dollars to the first friend.
  • A present that costs 1212 dollars to the second friend.
  • A present that costs 55 dollars to the third friend.
  • A present that costs 33 dollars to the fourth friend.
  • 55 dollars to the fifth friend.

In the second one, Petya has 55 and 55 available presents. Petya can spend only 190190 dollars if he gives

  • A present that costs 1010 dollars to the first friend.
  • A present that costs 4040 dollars to the second friend.
  • 9090 dollars to the third friend.
  • 4040 dollars to the fourth friend.
  • 1010 dollars to the fifth friend.

在第一个样例中,共有两个测试用例。在第一个测试用例中,Petya 有 55 位朋友和 44 个可用的礼物。若 Petya 给以下对象赠送礼物或金钱,则他仅需花费 3030 美元:

  • 给第一位朋友 55 美元;
  • 给第二位朋友一个价值 1212 美元的礼物;
  • 给第三位朋友一个价值 55 美元的礼物;
  • 给第四位朋友一个价值 33 美元的礼物;
  • 给第五位朋友 55 美元。

在第二个测试用例中,Petya 有 55 位朋友和 55 个可用的礼物。若 Petya 给以下对象赠送礼物或金钱,则他仅需花费 190190 美元:

  • 给第一位朋友一个价值 1010 美元的礼物;
  • 给第二位朋友一个价值 4040 美元的礼物;
  • 给第三位朋友 9090 美元;
  • 给第四位朋友 4040 美元;
  • 给第五位朋友 1010 美元。

输入解题思路,AI测评打分。不知道怎么写?

首页