#C9693. Calculate Employee Project Priorities

    ID: 53814 Type: Default 1000ms 256MiB

Calculate Employee Project Priorities

Calculate Employee Project Priorities

You are given n projects, each with an integer priority, and m employees. Each employee works on a subset of these projects. Your task is to compute the sum of the priorities of the projects assigned to each employee.

For each employee i, if the list of assigned projects is P_i, you need to calculate:

\( S_i = \sum_{j \in P_i} priority_j \)

Output the computed sum for each employee in the order they are provided.

inputFormat

The input is read from standard input and has the following format:

  1. An integer n representing the number of projects.
  2. A line with n space-separated integers representing the priority of each project.
  3. An integer m representing the number of employees.
  4. For each of the next m lines, the line begins with an integer k (the number of projects assigned to that employee), followed by k space-separated integers indicating the 0-indexed IDs of the projects.

outputFormat

Print a single line containing m integers separated by spaces. Each integer represents the total sum of project priorities for the corresponding employee.

## sample
4
10 20 30 40
3
2 1 2
3 0 2 3
1 3
50 80 40