#P9670. Reconstruct the Final Scoreboard

    ID: 22817 Type: Default 1000ms 256MiB

Reconstruct the Final Scoreboard

Reconstruct the Final Scoreboard

Two thousand years ago in the Qin dynasty an ICPC contest was held. There were \(m\) problems and \(n\) teams. The historical records preserved for each team only the final result of the contest, i.e. the total number of problems solved and the total time used. Recently a frozen scoreboard was discovered. For each team, the frozen scoreboard lists all submissions made during the contest; however, the verdicts of the submissions in the final hour (i.e. submissions with time between 240 and 299 minutes, inclusive) are missing.

From the submissions, a final scoreboard for a team is defined to be an array of \(m\) cells (one for each problem) as follows:

  • If no submission was made on problem \(j\), the cell is a single dot: .
  • If there were \(x\) submissions on problem \(j\) and none was accepted, the cell is -x.
  • If there is at least one accepted submission, let the earliest accepted submission be the \(x\)-th submission (when counting submissions for that problem in order) and let its submission time be \(y\) minutes (\(0 \le y \le 299\)). Then the cell is +x/y.

The final result for a team is obtained from its final scoreboard as follows:

  • The number of problems solved is the count of cells that start with a +.
  • For a solved problem whose final cell is +x/y, its time contribution is \(20(x-1)+y\). Unsolved problems contribute 0 time.
  • The team’s total time is the sum of time contributions from all problems.

For each problem of each team, submissions before 240 minutes (non-frozen) have known verdicts (A for accepted and R for rejected). Submissions in the final hour (with submission time 240 to 299) are recorded in the frozen scoreboard with a verdict of ?. For problems which do not have an accepted non-frozen submission but have frozen submissions, you may decide to mark exactly one of the frozen submissions as accepted — namely, the earliest frozen submission (if you choose to) — to try to match the team’s final result. Otherwise, all submissions are treated as rejections.

Given the final results for each team and their frozen scoreboards, construct a final scoreboard for each team that is consistent with both the final result and the frozen scoreboard.

Input/Output Formats are described below.

inputFormat

The input begins with two integers \(m\) and \(n\) representing the number of problems and teams respectively.

Then follow \(n\) lines, each containing two integers \(s\) and \(t\), representing the final solved count and the team’s total time according to the historical records.

For each team (in the same order as above), there are \(m\) blocks corresponding to the problems (from problem 1 to problem \(m\)). Each block is on a separate line and begins with an integer \(k\) (the number of submissions for that problem). If \(k > 0\), it is followed by \(k\) pairs. Each pair consists of an integer time (in minutes) and a string verdict. For submissions with time less than 240, verdict is either A (accepted) or R (rejected). For submissions with time in \([240, 299]\), the verdict is given as ? (meaning the verdict is unknown in the frozen scoreboard).

You may assume that the submissions for each problem are listed in the order they were made.

outputFormat

For each team, output a single line containing \(m\) cells separated by a single space. Each cell should be formatted as follows:

  • . if no submission was made for that problem.
  • -x if there were submissions but none was accepted (\(x\) is the total number of submissions for that problem).
  • +x/y if the problem was solved (\(x\) is the order index of the submission that was accepted and \(y\) is its submission time).

The final scoreboard constructed must be consistent with the team’s final result (number of solved problems and total time).

sample

2 2
1 50
1 245
2 10 R 250 ?
1 50 A
1 245 ?
2 30 R 290 ?
-2 +1/50

+1/245 -2

</p>