#B3682. Fragment Compensation in Personalized Treasure Draws

    ID: 11341 Type: Default 1000ms 256MiB

Fragment Compensation in Personalized Treasure Draws

Fragment Compensation in Personalized Treasure Draws

In a particular season of a game, there is a treasure chest known as Treasure that contains n distinct items. Each item has one of five qualities, and the items cannot be obtained repeatedly in the warehouse. When a player draws an item for the first time, the item is added to their warehouse. For any subsequent draws of the same item, the player does not obtain the item but instead receives a fragment compensation based on the item's quality.

The five qualities and their corresponding fragment compensation amounts are given in the following table:

Quality Fragment Compensation Quality Code
Gold $2000$ 1
Purple $1000$ 2
Blue $200$ 3
Green $36$ 4
White $6$ 5

A player, referred to as E, performs k draws from the treasure pool. The input provides:

  • An integer n, the total number of items in the pool.
  • An integer k, the number of draws made.
  • A list of n integers representing the quality codes of the items in the pool (in order from item 1 to item n).
  • A list of k integers representing the sequence of item indices drawn by E. Each drawn index is between 1 and n.

For each draw:

  • If the item is drawn for the first time, it is added to the player's warehouse and no fragments are awarded.
  • If it is a duplicate draw (i.e., the item is already in the warehouse), the player receives fragments equal to the compensation amount determined by the quality of that item.

Your task is to compute the total number of fragments that E receives after k draws.

inputFormat

The input consists of three lines:

  1. The first line contains two integers n and k separated by a space.
  2. The second line contains n integers. The ith integer represents the quality code (from 1 to 5) of the ith item in the pool.
  3. The third line contains k integers. Each integer is an index (between 1 and n) representing the item drawn in that operation.

outputFormat

Output a single integer representing the total number of fragments awarded to E.

sample

5 8
1 2 3 4 5
1 2 1 3 1 2 5 5
5006