Hide

Problem E
Heavy Events Ranking

/problems/heavyeventsranking/file/statement/en/img-0001.jpg
Image created using ChatGPT

In the highland games heavy events, athletes compete against each other in a medley of throwing-based events. This typically consists of $9$ traditional events: braemar, open stone, heavy weight for distance, light weight for distance, heavy hammer, light hammer, caber, weight over bar, and sheaf. Every athlete in a competition competes in each of these events, and in each one is ranked according to their performance and receives points corresponding to their rank, as follows: first place in an event earns $1$ point, second place earns $2$ points, third place earns $3$ points, etc. At the end of the competition, the points for a given athlete across all events are summed up, and the athlete with the lowest points total wins.

Ties need to be considered, though. If a tie happens in an event, then the relevant points are divided evenly across all those who tie. For example, if there is a two-way tie for third, then those two athletes will each receive $(3+4)/2$ points for that event. Likewise, if there is a three-way tie for sixth, each of the three athletes will receive $(6+7+8)/3$ points. (As is typical for ranked events, if $2$ athletes tie for position $p,$ then the next available position is $p+2,$ if $3$ athletes tie for position $p,$ then the next available position is $p+3,$ etc. So if two athletes tie for third, then the athlete with the next best ranking is in fifth place, not fourth.)

All heavy events are distance-based or height-based, and an athlete’s performance (or score) is measured in feet (a larger number is better), except for the caber, which is an accuracy-based event. For simplicity, we will omit the caber, leaving $8$ events in a single competition in which athletes need to be ranked in order to determine the overall winner. There may be many athletes in a competition, and manually determining who won can be very time consuming. Also, a person recording scores may simply write them down in a list without considering the order of events or the ranking of athletes in individual events. Therefore, it is your job to create a program that will decide who won a heavy events competition using a set of data containing each athlete’s score in each event.

Note that it may also be necessary to resolve ties when determining the overall winner. If two or more athletes share the same lowest points total, then the competition winner is the one who received the most first-place finishes in the $8$ events. If two or more of the leading athletes tie for first-place finishes, then their numbers of second-place finishes are compared, and if they also tie for second-place finishes, their numbers of third-place finishes are compared. If comparing third-place finishes is required and there is still a tie at that level, those athletes are considered to have tied as overall winners of the competition. An important detail in this process is that if there is a tie for the most $p\textrm{-place}$ finishes (with $p = 1$ or $p = 2),$ then only those who tied at that level are considered for their $(p+1)\textrm{-place}$ finishes.

Here is an example of determining the overall winner. Suppose three athletes, $A,$ $B,$ and $C,$ share the same lowest points total, and suppose none of them have any first-place finishes in the $8$ events. This means all three of them are tied for first-place finishes (with zero each), so it is necessary to compare their second-place finishes. Now suppose $A$ and $C$ have $5$ second-place finishes each, and $B$ $\textrm{has}~ 3.$ This means $B$ is removed from consideration, and we compare third-place finishes for $A$ and $C.$ If $A$ has $1$ third-place finish and $C$ has $2,$ then $C$ is the overall winner. If instead both have $2$ third-place finishes, then $A$ and $C$ tie as overall winners of the competition.

Input

The first line of input contains a single positive integer, $n \leq 50,$ the number of athletes in a heavy events competition. This is followed by $8n$ lines, each of which contains the information for the performance of one athlete in one event. Each such line contains three space-separated values, $a~ e~ s,$ where $a$ is the name of the athlete (a nonempty string of at most $25$ lowercase letters), $e$ is the name of the event (one of the following strings: braemar, open_stone, heavy_weight, light_weight, heavy_hammer, light_hammer, weight_over_bar, sheaf), and $s$ is the athlete’s score in that event (a real number in the range $0.0$ to $149.9,$ inclusive, with exactly one digit after the decimal place). All athletes’ names are distinct, and no athlete is named “tie” (relevant below). Each athlete will have exactly one score for each of the $8$ events.

Output

If the competition has a unique winner, output a line containing the name of the winning athlete followed by the athlete’s points total, separated by a space. If two or more athletes tie as overall winners (as described above), output a line containing the word “tie” followed by the shared lowest points total, separated by a space. In either case, the points total should be a real number with exactly one digit after the decimal place.

Sample Input 1 Sample Output 1
2
macearachar sheaf 33.6
macearachar open_stone 51.9
macearachar braemar 23.2
macearachar light_weight 80.2
mackieson heavy_hammer 74.3
macearachar light_hammer 18.9
mackieson heavy_weight 28.9
mackieson open_stone 30.9
mackieson light_weight 78.6
mackieson braemar 11.6
macearachar heavy_hammer 22.7
mackieson sheaf 21.7
macearachar heavy_weight 17.3
mackieson weight_over_bar 18.7
mackieson light_hammer 120.0
macearachar weight_over_bar 16.8
tie 12.0
Sample Input 2 Sample Output 2
3
balloch heavy_weight 18.9
maceachan heavy_weight 16.6
balloch weight_over_bar 11.4
macgrime heavy_hammer 52.8
macgrime sheaf 10.8
maceachan light_hammer 56.2
balloch open_stone 51.8
maceachan open_stone 41.6
maceachan sheaf 30.2
macgrime light_hammer 56.2
macgrime light_weight 47.9
balloch sheaf 42.4
maceachan heavy_hammer 92.5
macgrime weight_over_bar 12.4
macgrime braemar 28.8
balloch braemar 28.1
balloch light_weight 44.1
balloch heavy_hammer 36.6
balloch light_hammer 91.8
macgrime open_stone 18.3
macgrime heavy_weight 19.9
maceachan braemar 33.4
maceachan light_weight 71.4
maceachan weight_over_bar 15.4
maceachan 13.5

Please log in to submit a solution to this problem

Log in