#B4082. Contest Penalty Calculation
Contest Penalty Calculation
Contest Penalty Calculation
During the XCPC contest, a team can submit several times for each problem. A submission for a problem is considered effective if and only if:
- The team had not solved that problem before this submission.
- This submission eventually contributed to solving the problem.
For each problem solved by the team, all its effective submissions have exactly one accepted submission (the last one) and possibly several prior unsuccessful submissions. The penalty time for a problem is defined as:
[ \text{Penalty} = t + 20 \times k, ]
where:
- \(t\) is the time (in minutes) when the problem was first solved (i.e. the time of the accepted submission).
- \(k\) is the number of unsuccessful effective submissions for that problem before the accepted one.
The total penalty for a contest is the sum of the penalties of all solved problems.
Note: Although the penalty is defined per problem, the submission records given in the input do not include the problem identifier. In other words, each record is a pair \((a_i, b_i)\) where \(a_i\) is the submission time and \(b_i\) indicates the outcome (with 0 representing a wrong submission and 1 representing an accepted submission). It is guaranteed that the submissions in each problem’s effective record appear in order (with the last submission for that problem being accepted).
Your task is to calculate and output the total penalty for the team.
inputFormat
The first line contains a positive integer \(n\) indicating the number of effective submissions.
Each of the following \(n\) lines contains two integers \(a_i\) and \(b_i\) separated by a space, where \(a_i\) is the submission time in minutes and \(b_i\) is the verdict (0 for a wrong submission and 1 for an accepted submission).
It is guaranteed that for each problem solved, there is exactly one record with \(b_i = 1\) (the accepted submission) and possibly one or more records with \(b_i = 0\) before it.
outputFormat
Output a single integer — the total penalty time of the team.
sample
1
55 1
55