#K59422. Minimum Paint Capacity for Antenna Buildings

    ID: 30861 Type: Default 1000ms 256MiB

Minimum Paint Capacity for Antenna Buildings

Minimum Paint Capacity for Antenna Buildings

You are given a row of n buildings, where each building has a certain height. In addition, you are provided with a list of antenna indices (1-indexed) that indicate which buildings have antennas installed. The task is to calculate the minimum amount of paint required to paint all buildings that have an antenna.

The amount of paint required for a building is exactly equal to its height. Therefore, the answer is the sum of the heights of the buildings with antennas.

For example, if there are 5 buildings with heights [2, 5, 4, 3, 1] and antennas are installed on the buildings at indices 2 and 4, then the amount of paint needed is 5 + 3 = 8.

Note: All indices provided for antennas are 1-indexed, meaning that the first building is referred to by the index 1.

inputFormat

The input is read from standard input (stdin) and consists of four lines:

  1. The first line contains a single integer n — the number of buildings.
  2. The second line contains n space-separated integers, where the i-th integer represents the height of the i-th building.
  3. The third line contains a single integer k — the number of buildings that have antennas.
  4. The fourth line contains k space-separated integers, each representing a 1-indexed building number that has an antenna.

outputFormat

Print a single integer to standard output (stdout) — the minimum amount of paint required, which is the sum of the heights of the buildings with antennas.## sample

5
2 5 4 3 1
2
2 4
8