#K90537. Ranking Scores
Ranking Scores
Ranking Scores
You are given a list of scores. Your task is to compute:
- The number of unique scores.
- The list of unique scores sorted in decreasing order.
- A list of ranks corresponding to the original scores, where the rank is defined as the index of the score in the sorted unique list (starting from 0).
In other words, let \(S\) be your input list of scores. Let \(U\) be the set of unique scores in \(S\) arranged in decreasing order. Then:
\[ |U|,\quad U,\quad \text{ranks} = \{\text{index of } s \text{ in } U \;:\; s \in S\} \]For example, if the input scores are 100 200 300 200 100
, the sorted unique scores are 300 200 100
giving ranks of 2 1 0 1 2
for the original input.
inputFormat
The first line of input contains an integer \(n\) representing the number of scores. If \(n > 0\), the second line contains \(n\) space-separated integers representing the scores. If \(n = 0\), there is no second line.
Example: 5 100 200 300 200 100
outputFormat
The output consists of three lines:
- The first line contains an integer representing the number of unique scores.
- The second line contains the unique scores sorted in decreasing order, separated by a space. If there are no scores, this line will be empty.
- The third line contains the rank of each original score (as described above) in the order they appeared in the input, separated by a space. If there are no scores, this line will be empty.
Example Output: 3 300 200 100 2 1 0 1 2## sample
5
100 200 300 200 100
3
300 200 100
2 1 0 1 2
</p>