A regional archery federation records the precision score of every practice shot fired during a qualifying session. Precision scores are decimal values with exactly two digits after the decimal point, and a higher score means a more accurate shot. The federation wants a rank board where the single best shot is rank 1, and any shots that land on exactly the same score are given the exact same rank. Crucially, ranks must never skip a number just because of a tie -- the next distinct (strictly lower) score always receives the rank immediately following the last rank that was actually used.
Given every recorded shot from the session, print each shot's score together with its rank, ordered from the highest score to the lowest.
Print n lines. Sort the shots by score in descending order and, for each one (in that sorted order), print the score followed by a single space and its dense rank.
Example 1
Input
4 3.50 3.65 4.00 3.65
Expected
4.00 1 3.65 2 3.65 2 3.50 3
Explanation
The distinct scores sorted from highest to lowest are 4.00 (rank 1), 3.65 (rank 2, shared by both shots that scored it), and 3.50 (rank 3 -- the next rank after the tie, with no gap left for the skipped rank that the tie would otherwise have consumed). Printing the shots from highest to lowest score gives "4.00 1", "3.65 2", "3.65 2", "3.50 3".
Example 2
Input
1 7.00
Expected
7.00 1
Explanation
There is only one recorded shot, so it is automatically both the best and the worst, and it receives rank 1: "7.00 1".
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →