Pinball Ranking
InterviewTime limit1sMemory limit128 MB
Given scores in play order, compute each game's rank as one plus the number of earlier-or-later scores strictly above it, then output the average rank as a reduced fraction.
- Level
Medium5 of 10
- Topics
- Binary search, Sorting, Array, Implementation
- Solved
- No attempts yet
Problem
Pinball is an arcade game in which a player controls a silver ball with flippers, aiming to accumulate as many points as possible. At the end of each game, the player's score and rank are shown on the screen.
The score is the value achieved in the game just ended, an integer between and . The rank is shown in the form " of ", where is the total number of games ever played on the machine and is the position of this game's score within that whole set of games.
More precisely, is one greater than the number of games whose score is strictly higher than that of the game just ended.
Input
Implement the pinball machine's ranking algorithm.
The first line contains a positive integer , the total number of games ever played on the machine. Each of the following lines contains the score of one game, given in chronological order.
- At least one test case has ; every test case has .
Output
Output the average of the ranks displayed after the games, written as a reduced fraction .
Formally, let be the sum of all displayed ranks and the total number of games. Print the average in lowest terms as "". The denominator is always positive, and even when the average is an integer you must keep the denominator, printing it as "" (for example, an average of is printed as 2/1).
Note
For example, if the scores are in order, the pinball screen displays the following ranks after each game:
1 of 1
1 of 2
2 of 3
2 of 4
5 of 5
So the displayed ranks are , and their average is .
Equal scores do not exceed one another, so tied games never push each other down in the ranking.