ICPC Ranking
Time limit1sMemory limit128 MB
Simulate the ICPC log to score each team by solved problems and penalty time, then print the ordered ranking with ties marked.
- Level
Easy3 of 10
- Topics
- Simulation, Sorting, Implementation
- Solved
- No attempts yet
Problem
Read the submission log of an ICPC (International Collegiate Programming Contest) and determine the team rankings.
The log is a list of submission records in the order they were submitted. Each record has four fields: elapsed time, team number, problem number, and judgment. The elapsed time is the time from the start of the contest to that submission. The judgment tells whether the submitted program was correct or incorrect, and when it was incorrect, which kind of error was found.
The rankings follow the rules below. This rule set is the one used in the real ICPC World Finals and Regionals, with a few detail rules dropped for simplicity.
- A team that solved more problems ranks higher.
- Among teams that solved the same number of problems, the one with the smaller total consumed time ranks higher.
- If two or more teams solved the same number of problems and their total consumed times are equal, they get the same rank.
The total consumed time is the sum of the consumed time of every solved problem. The consumed time of a solved problem is the elapsed time of the accepted submission plus 20 penalty minutes for each earlier rejected submission on that problem.
The consumed time of an unsolved problem is zero, so any number of incorrect submissions on it costs nothing.
You can assume that a team never submits a program for a problem after a correct submission for the same problem.
Input
The input is a sequence of datasets, each in the format below. A line with four zeros follows the last dataset.
M T P R
m1 t1 p1 j1
m2 t2 p2 j2
.....
mR tR pR jR
The first line of a dataset contains four integers , , , and . is the duration of the contest, is the number of teams, is the number of problems, and is the number of submission records. These values satisfy , , , and . Team numbers run from 1 to , and problem numbers run from 1 to .
Each of the next lines holds one submission record as four integers , , , and (). is the elapsed time, is the team number, is the problem number, and is the judgment, where 0 means correct and any other value means incorrect. These values satisfy , , , and .
Elapsed times are rounded to the nearest minute.
Submission records come in submission order, so if then the -th submission happened before the -th one and . In some cases that fact would separate two teams whose times differ by less than a minute, but the ranking never uses it. Teams are ranked on time in minutes only.
Output
For each dataset, print the team numbers (1 to ) on one line, highest ranked team first. The separator between two team numbers is a comma. The separator between two teams that share a rank is an equal sign. Teams that share a rank are listed in decreasing order of team number.