#P6675. Worst Rank Possibility
Worst Rank Possibility
Worst Rank Possibility
A long‐running ACM contest has just finished. There were n teams competing over m problems. In particular, one of the contestants, team NijeZivotJedanACM, wants to know what is the worst possible ranking they might end up with after the scoreboard is unfrozen.
The contest uses the standard ACM scoring rules:
- Teams are ranked first by the number of solved problems (in non‐increasing order).
- If teams solve the same number of problems, they are ranked by their total penalty time (in non-decreasing order).
- If teams are still tied, they are ordered lexicographically by their team name.
For each solved problem the penalty time is:
$$\text{time}\; +\; 20\times(\text{wrong submissions before the correct one}) $$During the contest, in the first 4 hours all teams receive immediate feedback. In the final hour the scoreboard is frozen. During the freeze, every team sees the number of submissions they have made per problem, and for each problem the time of their last submission, but they do not see the judgement of other teams' freeze submissions. NijeZivotJedanACM has complete, up‐to‐date information about their own runs, while for every other team we only know their pre–freeze results as well as the following for each unsolved problem:
- The number of submissions made during the frozen period (let this be c).
- The last submission time in the frozen period (l minutes from contest start, where \(241 \le l \le 300\)).
If a problem was unsolved in the first 4 hours and a team made at least one submission during the frozen period, then in the worst‐case scenario (from the perspective of NijeZivotJedanACM) we assume that the submission eventually is judged as correct if the total number of submissions for that problem does not exceed 9. In other words, if a team had already made w submissions in the first 4 hours for that problem and then made c submissions in the freeze (c > 0), they will solve that problem during freeze if \(w + c \le 9\). The penalty time for a problem solved during freeze is calculated as:
Note that teams never submit a solution for a problem they have already solved.
Your task is to compute the worst possible rank of NijeZivotJedanACM after the scoreboard is unfrozen. The results for NijeZivotJedanACM are final and do not get any benefit from freeze submissions, while every other team is assumed to get all possible additional solves from their freeze submissions (subject to the 9 submission limit per problem).
inputFormat
The input starts with a line containing two integers n and m (the number of teams and problems).
This is followed by data for each of the n teams. For each team:
- A line with the team name (a string without spaces).
- m lines describing the pre‐freeze status for each problem. Each line contains three fields:
- An integer
s(1 if the problem was solved before freeze, 0 otherwise). - An integer
w(the number of submissions, i.e. the number of wrong attempts before a correct submission if solved, or the total attempts if unsolved). - A value representing the submission time in minutes if solved (an integer) or a dash (
-) if not solved.
- An integer
- m lines describing the freeze submissions for each problem. Each line contains two fields:
- An integer
c(the number of submissions during the freeze for that problem; 0 if none). - A value representing the time (in minutes) of the last freeze submission if any (or a dash (
-) ifcis 0).
- An integer
Note: The team NijeZivotJedanACM's freeze data does not affect their results.
Example format:
3 2 NijeZivotJedanACM 1 1 30 0 0 - 0 - TeamA 0 2 - 1 0 100 1 250 0 - TeamB 1 0 50 0 1 - 0 - 2 290
outputFormat
Output a single integer: the worst possible ranking (1-indexed) that team NijeZivotJedanACM can have after the scoreboard is unfrozen.
sample
3 2
NijeZivotJedanACM
1 1 30
0 0 -
0 -
TeamA
0 2 -
1 0 100
1 250
0 -
TeamB
1 0 50
0 1 -
0 -
2 2903