#K9946. Calculate Performance Scores
Calculate Performance Scores
Calculate Performance Scores
You are given a list of submissions from participants in a competition. Each submission is represented by a participant identifier and a score. For each participant, you need to calculate a performance score which is defined as the sum of the top three distinct scores. If a participant has fewer than three distinct scores, sum all of their distinct scores.
Formally, let \(S_i\) be the set of scores submitted by participant \(i\). The performance score for participant \(i\) is given by:
\[ score_i = \sum_{j=1}^{\min(3, |S_i|)} s_{ij}, \]
where \(s_{ij}\) denotes the \(j^{th}\) highest distinct score for participant \(i\).
Input is read from standard input and the result should be printed on standard output.
inputFormat
The first line of input contains two integers \(n\) and \(k\), where \(n\) is the number of participants and \(k\) is the total number of submissions. This is followed by \(k\) lines, each containing two integers \(p\) and \(s\) representing a submission by participant \(p\) with a score \(s\).
outputFormat
Output a single line containing \(n\) integers separated by spaces. The \(i^{th}\) integer represents the performance score for participant \(i\) (participants are numbered from 1 to \(n\)).
## sample3 8
1 50
1 90
1 80
1 50
2 100
2 30
2 30
3 60
220 130 60