#abc288e. E - Wish List

E - Wish List

Score : 500500 points

问题描述

在一家商店中有 NN 件商品,编号分别为 Item 11, Item 22, \ldots, Item NN
对于每个 i=1,2,,Ni = 1, 2, \ldots, N,Item ii常规价格AiA_i 日元。每种商品库存中只有一件。

高桥想要 MM 件商品:Item X1X_1, Item X2X_2, \ldots, Item XMX_M

他将重复以下操作直到获取所有他想要的商品:

rr 为当前未售出商品的数量。选择一个整数 jj 使得 1jr1 \leq j \leq r,然后以该商品的常规价格加上 CjC_j 日元的价格购买未售出商品中第 jj 小的商品编号对应的商品。

请输出获取高桥想要的所有商品所需的最小总金额。

高桥也可以购买他不想要的商品。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are NN items in a shop, numbered as Item 11, Item 22, \ldots, Item NN.
For each i=1,2,,Ni = 1, 2, \ldots, N, the regular price of Item ii is AiA_i yen. For each item, there is only one in stock.

Takahashi wants MM items: Item X1X_1, Item X2X_2, \ldots, Item XMX_M.

He repeats the following until he gets all items he wants.

Let rr be the number of unsold items now. Choose an integer jj such that 1jr1 \leq j \leq r, and buy the item with the jj-th smallest item number among the unsold items, for its regular price plus CjC_j yen.

Print the smallest total amount of money needed to get all items Takahashi wants.

Takahashi may also buy items other than the ones he wants.

Constraints

  • 1MN50001 \leq M \leq N \leq 5000
  • 1Ai1091 \leq A_i \leq 10^9
  • 1Ci1091 \leq C_i \leq 10^9
  • 1X1<X2<<XMN1 \leq X_1 \lt X_2 \lt \cdots \lt X_M \leq N
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN MM

A1A_1 A2A_2 \ldots ANA_N

C1C_1 C2C_2 \ldots CNC_N

X1X_1 X2X_2 \ldots XMX_M

Output

Print the answer.

Sample Input 1

5 2
3 1 4 1 5
9 2 6 5 3
3 5

Sample Output 1

17

Here is a way for Takahashi to get all items he wants with the smallest total amount of money.

  • Initially, five items, Items 1,2,3,4,51, 2, 3, 4, 5, are remaining. Choose j=5j = 5 to buy the item with the fifth smallest item number among the remaining, Item 55, for A5+C5=5+3=8A_5 + C_5 = 5 + 3 = 8 yen.
  • Then, four items, Items 1,2,3,41, 2, 3, 4, are remaining. Choose j=2j = 2 to buy the item with the second smallest item number among the remaining, Item 22, for A2+C2=1+2=3A_2 + C_2 = 1 + 2 = 3 yen.
  • Then, three items, Items 1,3,41, 3, 4, are remaining. Choose j=2j = 2 to buy the item with the second smallest item number among the remaining, Item 33, for A3+C2=4+2=6A_3 + C_2 = 4 + 2 = 6 yen.

Now, Takahashi has all items he wants, Items 33 and 55, (along with Item 22, which is not wanted) for a total cost of 8+3+6=178 + 3 + 6 = 17 yen, the minimum possible.

Sample Input 2

20 8
29 27 79 27 30 4 93 89 44 88 70 75 96 3 78 39 97 12 53 62
32 38 84 49 93 53 26 13 25 2 76 32 42 34 18 77 14 67 88 12
1 3 4 5 8 14 16 20

Sample Output 2

533

update @ 2024/3/10 12:02:28