C - Turn into Money Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

問題文

高橋君は N 枚のカードを持っています。
i = 1, 2, \ldots, N について、高橋君が持っている i 枚目のカードには 1 以上 10 以下の整数 A_i が書かれています。

x = 1, 2, \ldots, 10 について、整数 x が書かれたカードは 1 枚ごとに P_x 円に換金できます。
高橋君が持っているカード全てを換金するときに得られる合計金額を出力してください。

制約

  • 1 \leq N \leq 10
  • 1 \leq A_i \leq 10
  • 1 \leq P_x \leq 10^9
  • 入力はすべて整数

入力

入力は以下の形式で標準入力から与えられる。

N
A_1 A_2 \ldots A_N
P_1 P_2 \ldots P_{10}

出力

答えを整数として出力せよ。


入力例 1

4
3 10 7 3
31 41 59 26 53 58 97 93 23 84

出力例 1

299
  • 1 枚目のカードには整数 3 が書かれています。よって、P_3 = 59 円に換金できます。
  • 2 枚目のカードには整数 10 が書かれています。よって、P_{10} = 84 円に換金できます。
  • 3 枚目のカードには整数 7 が書かれています。よって、P_7 = 97 円に換金できます。
  • 4 枚目のカードには整数 3 が書かれています。よって、P_3 = 59 円に換金できます。

よって、高橋君が持っているカード全てを換金するときに得られる合計金額は、 59 + 84 + 97 + 59 = 299 円です。


入力例 2

10
7 7 7 7 7 7 7 7 7 7
1 1 1 1 1 1 1000000000 1 1 1

出力例 2

10000000000

答えが 32 bit整数型に収まらないこともあります。

Problem Statement

Takahashi has N cards.
For i = 1, 2, \ldots, N, his i-th card has an integer A_i between 1 and 10 written on it.

For x = 1, 2, \ldots, 10, a card with the integer x written on it can be changed into P_x yen (currency in Japan).
Find the total amount of money Takahashi can get by changing all his cards into money.

Constraints

  • 1 \leq N \leq 10
  • 1 \leq A_i \leq 10
  • 1 \leq P_x \leq 10^9
  • All input values are integers.

Input

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

N
A_1 A_2 \ldots A_N
P_1 P_2 \ldots P_{10}

Output

Print the answer as an integer.


Sample Input 1

4
3 10 7 3
31 41 59 26 53 58 97 93 23 84

Sample Output 1

299
  • The 1-st card has an integer 3 written on it, which is worth P_3 = 59 yen.
  • The 2-nd card has an integer 10 written on it, which is worth P_{10} = 84 yen.
  • The 3-rd card has an integer 7 written on it, which is worth P_7 = 97 yen.
  • The 4-th card has an integer 3 written on it, which is worth P_3 = 59 yen.

Thus, he can change all his cards into money to get a total of 59 + 84 + 97 + 59 = 299 yen.


Sample Input 2

10
7 7 7 7 7 7 7 7 7 7
1 1 1 1 1 1 1000000000 1 1 1

Sample Output 2

10000000000

The answer may not fit into a 32-bit integer type.