Contest Ranking
Time limit1sMemory limit256 MB
Parse each team per-problem records, sum the weights of solved problems, and print teams ranked by points with ties sharing a rank.
- Level
Easy3 of 10
- Topics
- Implementation, Sorting
- Solved
- No attempts yet
Problem
The contest system PC^2 was written for contests where each solved problem scores 1 point and time breaks ties. To use it in a contest where problems carry different weights, a program has to read the records PC^2 left behind and apply a different rule.
You are given the records of several contests. Each contest comes with the points every problem is worth and one submission record per team. Rank the teams by the rules of the contest they competed in.
Input
The input holds several contests. The first line of each contest has one integer , the number of problems (). A line holding 0 ends the input.
The second line has positive integers separated by spaces, one per problem. They give the points for the first problem, the second problem, and so on.
The third line of each contest has one integer , the number of teams taking part ().
Then come lines, one team per line. A line starts with the team name. The name may contain spaces but no comma, and a comma ends it. After the name comes one record per problem, records separated by commas. The records follow the order of the points on the second line, the first problem first.
Each record has one integer, a slash character /, and then either another integer or a - character. Read a record like this:
- The first integer is how many submissions the team made for that problem. It is 0 or more.
- If the slash is followed by
-, the team did not solve the problem and scores no points for it. - If the slash is followed by an integer, which is 0 or more, the team solved the problem. The number is how many minutes into the contest the successful submission arrived.
Output
For each contest, start the output with a line holding Contest N, where is the number of the contest. The first contest in the input is 1, and contests are numbered in the order they appear.
Then print one line per team with the rank, the team name and the points scored, separated by single spaces. List the teams in ascending order of rank.
A team with more points comes first. Teams with equal points share a rank and are printed in alphabetical order of name, ignoring case. If two names are equal once case is ignored, print them in alphabetical order of the original name. The rank of the team after a shared rank skips by the number of teams ahead of it. For example, when two teams share rank 1, the next team is rank 3.
Do not print a blank line between contests.