#K2946. Calculate Total Scores
Calculate Total Scores
Calculate Total Scores
You are given the scores for q problems and p participants. Each participant has a list of problems they solved. The list starts with a number k denoting how many problems they solved followed by k integers representing the indices of the solved problems. Your task is to calculate the total score for each participant based on the scores of the problems they solved.
The score for a participant is the sum of the scores of the problems they solved. Note that the problem indices are 1-indexed and the scores are provided in the order of the problem indices.
Input/Output: You will read input from stdin and output your results to stdout, with each participant's total score on a separate line.
inputFormat
The first line contains two space-separated integers p
and q
, where p
is the number of participants and q
is the number of problems.
The next q
lines each contain one integer representing the score for each problem (in order).
The following p
lines describe each participant. Each line starts with an integer k
which indicates the number of problems the participant solved, followed by k
integers which are the indices of the problems solved.
outputFormat
Output p
lines, each containing a single integer. The i-th line is the total score for the i-th participant.
3 4
10
20
30
40
2 1 3
3 2 3 4
1 4
40
90
40
</p>