Programming competitions are fun and exciting. Programming should be an Olympic sport! At least, this is what we believe. However, when we suggested this to some of our friends, they did not seem to share our excitement. So, we decided to suggest a combined sport that will be more interesting to watch. Programming-trampoline-athlon! (we are still working on the name.)
The idea is as follows. This is a team sport, where each team comprises of 3 members. The team has at its disposal 1 hour, 1 computer, and 1 trampoline. At all times, there must be at most one team member using the computer and at least one team member jumping the trampoline. At the beginning of the competition, the team is given 6 programming problems, and 6 trampoline elements (exercises). The team decides how to partition the trampoline elements between its members, such that each team member has to perform 2 of the given elements on the trampoline. The programming tasks are solved cooperatively by the team members, but no one member can spend more than 25 minutes on the computer in total. The scoring is comprised of two parts, which are added together:
Before we pitch this new sport to the International Olympic Committee, we want everything to be ready in order to show them just how serious we are. Thus, each team should receive a medal when no more than two other teams obtained a strictly higher score. However, in order to cope with a recent shortage of medals, the jury was instructed to make sure that there would be no more than 1 000 teams deserving a medal. We ask you to write a program that determines the medallists, given the performance of the different teams.
The first line contains the number $$$N$$$ of competing teams. Then follow $$$N$$$ lines. Each of these lines describes a team and contains space-separated values $$$C, P, E_1, E_2, E_3, E_4, E_5, E_6$$$; $$$C$$$ is a five-letter code used to identify the team, $$$P$$$ is an integer specifying the number of problems the team solved, and $$$E_i$$$ is an integer specifying the execution score of trampoline element number $$$i$$$.
Limits
The output should contain $$$M$$$ lines, where $$$M$$$ is the number of medallists. Each line should represent a medallist team, by containing two space-separated values $$$C$$$ and $$$S$$$, where $$$C$$$ is the team code and $$$S$$$ is the total score of the team. Medallist teams should be listed by decreasing total score and, in case of ties, by input order.
5 EMAIL 3 5 6 7 8 9 10 CRASH 2 7 1 8 2 8 1 MOUSE 4 0 9 3 9 1 7 SWERC 6 3 1 4 1 5 9 PAINT 6 0 0 0 0 0 10
SWERC 73 EMAIL 60 MOUSE 60 PAINT 60
4 CRAZY 4 0 2 4 6 8 10 JAZZY 2 9 9 9 9 9 9 JUICY 3 2 9 10 9 10 1 FUZZY 5 0 1 1 2 3 5
CRAZY 60 JUICY 60 FUZZY 57