#K8266. Participant Ranking
Participant Ranking
Participant Ranking
You are given the number of participants N and their scores as a list of integers. Your task is to determine the ranking for each participant, where a participant's rank is determined by the following rules:
- The participant with the highest score is ranked 1.
- If two or more participants have the same score, they share the same rank.
- The next participant (or group) receives a rank which is equal to their 1-based position when the list of scores is sorted in non-increasing order.
The ranking method can be formally described as follows. Let \(s_1, s_2, \dots, s_N\) be the scores of the participants. Let \(p\) be a permutation of \(\{1, 2, \dots, N\}\) so that: \[ s_{p_1} \ge s_{p_2} \ge \dots \ge s_{p_N} \] Then, the rank \(r_{p_i}\) for the participant in the position \(i\) is defined by: \[ r_{p_i} = 1 + \text{number of participants with a strictly higher score}\]
inputFormat
The input is read from stdin
and consists of two lines:
- The first line contains an integer N representing the number of participants.
- The second line contains N space-separated integers representing the scores of the participants.
outputFormat
Output a single line to stdout
with N space-separated integers, where the i-th integer represents the rank of the i-th participant.
5
10 20 20 5 15
4 1 1 5 3
</p>