Parliamentary Rankings
Time limit2sMemory limit512 MB
Given members and weekly action codes with point values, print the highest and lowest scores with the matching names in id order.
- Level
Easy3 of 10
- Topics
- Hash map, Sorting, Implementation
- Solved
- No attempts yet
Problem
A group of journalists decided to rank how the members of parliament performed each week, and asked you to write the program that produces the ranking.
The journalists picked a code for every action they consider noteworthy and attached a number of points to it. Some values are positive and some are negative. The table below lists the actions in force now. More will be added if the scheme catches on, but only these seven appear in the input.
Input
The input holds the data for one week.
The first line contains , the number of members who attended the chamber that week ().
Each of the next lines describes one member: a unique identifying number (), one space, then the member's name. The identifying numbers are distinct and a name is at most 20 characters long. A name may contain spaces.
The next line contains , the number of recorded actions ().
Each of the following lines describes one action: the member's identifying number, one space, then one letter code from the table above. The number always belongs to a member who attended.
A member's score for the week is the sum of the points of the actions recorded for that member. A member with no recorded action scores 0.
Output
On the first line print the highest score and the names of the members who scored it. On the second line print the lowest score and the names of the members who scored it.
Each line starts with the score, followed by the matching names in increasing order of identifying number, separated by one space. When the highest and the lowest score are equal, the two lines have the same content.
Hint
If every member has the same score, all of them are both the best scoring and the worst scoring. Both lines are still printed, so the same line appears twice.