Ranking List
Time limit1sMemory limit128 MB
Build a contest scoreboard: rank teams by solved problems then total time, with ties sharing a rank and listed alphabetically.
- Level
Medium4 of 10
- Topics
- Sorting, Implementation, Simulation
- Solved
- No attempts yet
Problem
Write a program that produces the ranking list for a programming contest. You are given the list of participating teams and a log describing every solution the teams submitted.
Scoring follows these rules:
- Teams are ranked by the total number of problems they solved correctly (more solved problems is better).
- Teams that solved the same number of problems are ranked by least total time.
- The total time is the sum of the time consumed over each solved problem. The time consumed for a solved problem is the number of minutes from the start of the contest until the accepted submission, plus 20 penalty minutes for every rejected submission for that problem (regardless of when the rejected run was submitted). A problem that is never solved consumes no time.
The detailed tie-break procedure for equal total times is intentionally not part of this task. Instead, if two or more teams have both the same number of solved problems and the same total time, assign them the same rank and list them in alphabetical order.
A team's rank means that exactly teams did better, so ranks are skipped whenever a tie occurs. For example, if the two best teams have identical solved counts and total times, they both receive rank and the next team receives rank — no team is assigned rank .
Finally, there is no penalty for a rejected submission made after a correct submission has already been accepted from the same team for the same problem.
Input
The first line contains the number of scenarios.
Each scenario begins with a line containing the number of teams (), followed by lines with the teams' distinct names, given in alphabetical order. A team name is a single word of at most 8 characters containing only letters and digits.
The next line contains the number of problems and the number of submitted solutions (, ). Each of the following lines describes one submission in the format problem time correctness team, where is the problem number, is the number of minutes elapsed since the contest started, correctness is either Yes or No, and team is the name of the submitting team. The submissions are sorted by time.
Output
For each scenario, print a ranking list containing every participating team. Each line has the format rank. team solved time, where rank is the team's rank, team is its name, solved is the number of problems it solved, and time is its total time.
The four fields are separated by single spaces and use fixed field widths: 2 for the rank, 8 for the team name, 1 for the number of solved problems, and 4 for the total time. Names are left-adjusted and numbers are right-adjusted (see the sample output).
Separate the ranking lists of consecutive scenarios with a blank line.