2005 Canadian Computing Competition, Stage 1

Problem S5: Pinball Ranking

Pinball is an arcade game in which an individual player controls a silver ball by means of flippers, with the objective of accumulating as many points as possible. At the end of each game, the player's score and rank are displayed. The score, an integer between 0 and 1 000 000 000, is that achieved by the player in the game just ended. The rank is displayed as "r of n". n is the total number of games ever played on the machine, and r is the position of the score for the just-ended game within this set.

More precisely, r is one greater than the number of games whose score exceeds that of the game just ended.

Input

You are to implement the pinball machine's ranking algorithm. The first line of input contains a positive integer, t, the total number of games played in the lifetime of the machine. t lines follow, given the scores of these games, in chronological order.

Output

You are to output the average of the ranks (rounded to two digits after the decimal) that would be displayed on the board.
At least one test case will have t ≤ 100. All test cases will have t ≤ 100 000.

Nice that you learned how to code a binary search tree. So, Jacob tried the same, and he also got only 90/100. The last test case is specially designed to be worst-case in terms of runtime, so you probably can't pass it using a binary search tree. Try a different approach.

Nice that you learned how to code a binary search tree. So, Jacob tried the same, and he also got only 90/100. The last test case is specially designed to be worst-case in terms of runtime, so you probably can't pass it using a binary search tree. Try a different approach.

Since the recent grading system change, execution times are now recorded more accurately. We noticed that certain O(N^2) algorithms were previously able to pass, so the time limit has been adjusted accordingly.

Since the recent grading system change, execution times are now recorded more accurately. We noticed that certain O(N^2) algorithms were previously able to pass, so the time limit has been adjusted accordingly.

An issue has recently come up with Java rounding a real number differently than C++:
One of the cases has an answer which evaluates to *exactly* ?.?45. This should be rounded DOWN to ?.?4, not up to ?.?5.

An issue has recently come up with Java rounding a real number differently than C++:

One of the cases has an answer which evaluates to *exactly* ?.?45. This should be rounded DOWN to ?.?4, not up to ?.?5.

It turns out that the result ?.?5 is produced when C++ long doubles are used (or similar higher-precision real variables in other languages), instead of just doubles. This absolutely seems like it should be correct. However, for convenience, we'll continue to go with the answer ?.?4.

It turns out that the result ?.?5 is produced when C++ long doubles are used (or similar higher-precision real variables in other languages), instead of just doubles. This absolutely seems like it should be correct. However, for convenience, we'll continue to go with the answer ?.?4.

glibc uses the [url=http://en.wikipedia.org/wiki/Rounding#Round_half_to_even]round half to even[/url] convention. This is now [url=http://wcipeg.com/wiki/Judge:Writing#Output]officially endorsed[/url].

[quote]More precisely, r is one greater than the number of games whose score exceeds that of the game just ended.[/quote]The problem statement tells you exactly how the rank is defined. Determining from the problem statement whether this means there are ties, or however you want to put it, is part of the contest coder's skill set (and also serves the programmer well in real life, in which project specifications are often written by incompetent managers).

More precisely, r is one greater than the number of games whose score exceeds that of the game just ended.

The problem statement tells you exactly how the rank is defined. Determining from the problem statement whether this means there are ties, or however you want to put it, is part of the contest coder's skill set (and also serves the programmer well in real life, in which project specifications are often written by incompetent managers).

Actually there is one solution that uses mergesort.
However, you have to be extremely clever with mergesort - this solution only sorts once (instead of [i]t[/i] times), the entire list of scores. If you sort [i]t[/i] times, as you normally would, you'll still TLE.

Actually there is one solution that uses mergesort. However, you have to be extremely clever with mergesort - this solution only sorts once (instead of t times), the entire list of scores. If you sort t times, as you normally would, you'll still TLE.