Outstanding Outcome
Time limit1sMemory limit2048 MB
Given a frozen scoreboard with pending submissions, find the lowest rank our team can end up at after the unfreeze.
- Level
Medium4 of 10
- Topics
- Greedy, Sorting, Implementation
- Solved
- No attempts yet
Statement
A programming contest for children and teens up to six years old is about to start. It is organized by ACM (Avijatičarski Centar Metković) and by no one else. teams will compete. Among them is the golden trio of young Croatian aviators, Paula, Marin, and Josip (listed in reverse alphabetical order; any resemblance to real people and events is not a coincidence). The format is standard, except that the team captain performs pirouettes, the co-pilot reads the problems in Russian, and dictates the code in Morse code to a programmer outside the plane, who is securely tied on with sticky tape.
The teams cross lances (more precisely, wings) on different problems. On the scoreboard, teams are sorted in descending order by the number of solved problems.
Teams with the same number of solved problems are sorted in ascending order by penalty time. A team's penalty time is the sum of the penalty times of its accepted problems. The penalty time of an accepted problem is the time of the last submission for that problem, plus 20 minutes for each wrong submission on that problem. A team does not submit to a problem it has already solved. A team may submit at most 9 times to the same problem. If two teams have the same number of solved problems and the same penalty time, they are sorted alphabetically by name.
The contest lasts five hours. For the first four hours, the scoreboard is visible to all teams and shows, for each problem, the total number of submissions, whether it is solved, and when. During these four hours, the ranking updates automatically with every submission. After four hours, the scoreboard freezes and keeps the order it had. During the last hour, each team knows the correctness of only its own submissions, but every team's scoreboard keeps updating the total number of submissions and the time of the last submission for each problem.
The contest is over, and the scoreboard will be unfrozen soon. Our team, NijeZivotJedanACM, wants to know the lowest possible position it can end up in after the unfreeze. Five hours of spinning under the blue sky left them too dizzy to write the program themselves, so please help them.
Input
The first line contains natural numbers () and ().
The next lines contain the frozen scoreboard at the end of the contest. Each line starts with a team name, made only of English uppercase and lowercase letters, at most 20 characters long. All team names are distinct. The name is followed by space-separated tokens, in order from the first problem to the last. Each token has the form SX/V.
S is the submission state. + means the problem is solved, - means it is not solved, and ? means the last submission was sent after the freeze.
X is the total number of submissions the team made to that problem. It is omitted when it is zero.
V is the time of the last submission in HH:MM:SS format (with leading zeros), and it is less than 5 hours. The /V part is omitted when the problem is not solved correctly.
The last line describes our team, NijeZivotJedanACM, after the unfreeze, in the same format.
Output
Print one line with the lowest possible position the team can finish at after the scoreboard is unfrozen.
Hints
Explanation of the first input: after the unfreeze, the scoreboard stays the same as it was while frozen, so our team is first.
Explanation of the second input: in the worst case, our team loses only to StoJeZivot and finishes second.
Explanation of the third input: in the worst case, our team loses to NisamSadaNistaDonio and JeLiMojKockaSeUmio and finishes third.