#K39692. Final Score Calculation
Final Score Calculation
Final Score Calculation
You are given the number of participants \(n\) and the number of problems \(m\). Each problem has an associated point value given in an array. You are also given a list of submissions. Each submission is a pair of integers \((p, q)\) which indicates that participant \(p\) solved problem \(q\). Note that if a participant makes multiple submissions for the same problem, the points are added each time.
The final score for each participant is the sum of the points for every submission they made. For a participant with no submissions, the score remains \(0\).
Task: Compute and output the final scores of all participants. The participants are numbered from \(1\) to \(n\), and the problems are numbered from \(1\) to \(m\).
Formula: The score for participant \(p\) is given by:
[ \text{score}p = \sum{(p,q) \in S} \text{points}[q-1] ]
where \(S\) is the set of all submissions.
inputFormat
The input is given via standard input (stdin) and has the following format:
- The first line contains two integers \(n\) and \(m\): the number of participants and the number of problems respectively.
- The second line contains \(m\) integers, where the \(i\)-th integer represents the points for the \(i\)-th problem.
- The third line contains an integer \(k\), representing the number of submissions.
- The following \(k\) lines each contain two integers \(p\) and \(q\), indicating that participant \(p\) solved problem \(q\).
Assume that \(1 \le p \le n\) and \(1 \le q \le m\).
outputFormat
Output a single line containing \(n\) integers separated by a space. The \(i\)-th integer is the final score of the \(i\)-th participant.
## sample5 4
3 6 2 7
6
1 2
2 1
1 3
3 2
4 4
2 4
8 10 6 7 0