Happiness
Time limit5sMemory limit256 MB
Given other teams' submission data, choose the order Pang solves his known problems (each takes a fixed time plus 20 penalty per rejection) to maximize his total happiness from ranking, medals, and special first/last-solve bonuses.
- Level
Hard8 of 10
- Topics
- Brute force, Sorting, Simulation, Implementation
- Solved
- No attempts yet
Problem
Pang graduated from college years ago and really misses the time he spent with ICPC (Interspecies Collegiate Pokemon Camp).
A contest in ICPC has problems. participating teams have minutes to solve them. After the contest, teams are ranked by the number of problems solved. Teams that solve the same number of problems are ranked by least total time. The total time is the sum of the time consumed for each problem solved. The time consumed for a solved problem is the time elapsed from the beginning of the contest to the submission of the first accepted run plus penalty minutes for every previously rejected run for that problem. No time is consumed for a problem that is not solved. If two teams tie, their solution time lists are computed. A team's solution time list is the list of the solution times of all problems solved by that team, sorted in descending order. The solution time of a problem is the time elapsed from the beginning of the contest to the submission of the first accepted run of that problem. (No penalty is added to the solution time.) The team with the lexicographically smaller solution time list has the better rank. A list is lexicographically smaller than if there is an integer such that and for every integer . If teams still tie, Pang's team is considered to have the better rank.
After the ranks are determined, prizes are awarded. Initially, a team with rank gets happiness. Then medals are awarded. Teams with rank to get a gold medal. The happiness of receiving a gold medal is . Teams with rank to get a silver medal. The happiness of receiving a silver medal is . Teams with rank to get a bronze medal. The happiness of receiving a bronze medal is . Besides medals, for each problem, the team that solved it first gets happiness. The team that has at least one solution and the smallest solution time among all teams and all problems gets an extra happiness. The team that has at least one solution and the largest solution time among all teams and all problems gets an extra happiness. In case of a tie, Pang's team always gets the happiness.
There were teams in the contest Pang participated in. He remembers every submission (time and verdict) of every other team. For each problem, he also remembers whether he knew how to solve it, and the number of rejected runs and the time he needed to solve it.
If Pang solved the problems in the wisest order, what is the maximum happiness he could get? Pang cannot solve any problem after minutes from the beginning of the contest (he can solve a problem at exactly 300 minutes). Once Pang solves a problem, he must submit it immediately and solve another one. He cannot postpone his submission to get the last submission happiness.
Input
The first line contains an integer , the number of teams (, is a multiple of ).
Each of the next lines describes one team and contains the statuses of the problems. For each problem, if it is not solved by the team, the status is a single character "-". Otherwise, the status contains two integers and separated by a single space, the solution time and the number of rejected runs before the solution time (). Statuses of different problems are separated by ",".
The last line describes Pang's team. For each problem, if Pang did not know how to solve it, the status is a single character "-". Otherwise, the status contains two integers and separated by a single space, the time he needs and the number of rejected runs before he can solve it (). Statuses of different problems are separated by ",".
There are no extra spaces or other characters in the statuses of Pang and the other teams.
Output
Output one integer: the maximum happiness.